package com.huabo.system.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.nio.channels.FileChannel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import javax.annotation.Resource;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricProcessInstanceQuery;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.ServletConfigAware;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblAttachment;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.FtpUtil;
import com.hbfk.util.JedisUtil;
import com.hbfk.util.JsonBean;
import com.hbfk.util.PageInfo;
import com.hbfk.util.PropertyFileReader;
import com.huabo.system.config.DateBaseConfig;
import com.huabo.system.manager.FileManager;
import com.huabo.system.mysql.entity.NodeMySql;
import com.huabo.system.mysql.entity.ProcessSettingMySql;
import com.huabo.system.mysql.entity.TblAccBookMySql;
import com.huabo.system.mysql.entity.TblAuditOptionMySql;
import com.huabo.system.mysql.entity.TblBiChartMySql;
import com.huabo.system.mysql.entity.TblBiCkEchartsMySql;
import com.huabo.system.mysql.entity.TblBiReportMenuMySql;
import com.huabo.system.mysql.entity.TblCirculationMySql;
import com.huabo.system.mysql.entity.TblContractTypeofMySql;
import com.huabo.system.mysql.entity.TblControlmatrixMySql;
import com.huabo.system.mysql.entity.TblCourseMySql;
import com.huabo.system.mysql.entity.TblExternalExpertMySql;
import com.huabo.system.mysql.entity.TblFinanceDataMySql;
import com.huabo.system.mysql.entity.TblFlowBussinessMySql;
import com.huabo.system.mysql.entity.TblFlowIOuterruleMySql;
import com.huabo.system.mysql.entity.TblFlowInnerRuleMySql;
import com.huabo.system.mysql.entity.TblFlowMySql;
import com.huabo.system.mysql.entity.TblFlowdesMySql;
import com.huabo.system.mysql.entity.TblHomePageModelMySql;
import com.huabo.system.mysql.entity.TblIndicatorMySql;
import com.huabo.system.mysql.entity.TblIndustryInnerMySql;
import com.huabo.system.mysql.entity.TblInnerruleMySql;
import com.huabo.system.mysql.entity.TblJobMySql;
import com.huabo.system.mysql.entity.TblLoginTypeMySql;
import com.huabo.system.mysql.entity.TblManageRightMySql;
import com.huabo.system.mysql.entity.TblManageUserBookMySql;
import com.huabo.system.mysql.entity.TblMonitorRuleMySql;
import com.huabo.system.mysql.entity.TblMonitorSolutionMySql;
import com.huabo.system.mysql.entity.TblMonitorSolutionresultMySql;
import com.huabo.system.mysql.entity.TblMyTaskMySql;
import com.huabo.system.mysql.entity.TblNbsjAuditplanMySql;
import com.huabo.system.mysql.entity.TblNbsjPlanprojectMySql;
import com.huabo.system.mysql.entity.TblNbsjProjectMySql;
import com.huabo.system.mysql.entity.TblNbsjSheetMySql;
import com.huabo.system.mysql.entity.TblNbsjSheetReportMySql;
import com.huabo.system.mysql.entity.TblOrgNoMySql;
import com.huabo.system.mysql.entity.TblOrgRightMySql;
import com.huabo.system.mysql.entity.TblOrgRightnewMySql;
import com.huabo.system.mysql.entity.TblOrganizationMySql;
import com.huabo.system.mysql.entity.TblOuterruleMySql;
import com.huabo.system.mysql.entity.TblProcessAnalysisMySql;
import com.huabo.system.mysql.entity.TblRiskFlowMySql;
import com.huabo.system.mysql.entity.TblRiskMySql;
import com.huabo.system.mysql.entity.TblRiskeventMySql;
import com.huabo.system.mysql.entity.TblRoleMySql;
import com.huabo.system.mysql.entity.TblStaffMySql;
import com.huabo.system.mysql.entity.TblSystemModuleMySql;
import com.huabo.system.mysql.entity.TblVersionMySql;
import com.huabo.system.mysql.entity.TblVideoTypeMySql;
import com.huabo.system.mysql.entity.TblYyUserOrderMySql;
import com.huabo.system.mysql.entity.TblYyUserQueryMySql;
import com.huabo.system.mysql.mapper.TblMyTaskMySqlMapper;
import com.huabo.system.oracle.entity.Find;
import com.huabo.system.oracle.entity.Node;
import com.huabo.system.oracle.entity.ProcessSetting;
import com.huabo.system.oracle.entity.RiskClass;
import com.huabo.system.oracle.entity.TblAccBook;
import com.huabo.system.oracle.entity.TblAssessTarget;
import com.huabo.system.oracle.entity.TblAuditOption;
import com.huabo.system.oracle.entity.TblBiChart;
import com.huabo.system.oracle.entity.TblBiCkEcharts;
import com.huabo.system.oracle.entity.TblBiReportMenu;
import com.huabo.system.oracle.entity.TblCirculation;
import com.huabo.system.oracle.entity.TblContractTypeof;
import com.huabo.system.oracle.entity.TblControlmatrix;
import com.huabo.system.oracle.entity.TblCourse;
import com.huabo.system.oracle.entity.TblCwsjDscjInfo;
import com.huabo.system.oracle.entity.TblExternalExpert;
import com.huabo.system.oracle.entity.TblFinanceData;
import com.huabo.system.oracle.entity.TblFlow;
import com.huabo.system.oracle.entity.TblFlowBussiness;
import com.huabo.system.oracle.entity.TblFlowIOuterrule;
import com.huabo.system.oracle.entity.TblFlowInnerRule;
import com.huabo.system.oracle.entity.TblFlowdes;
import com.huabo.system.oracle.entity.TblHomePageModel;
import com.huabo.system.oracle.entity.TblImplog;
import com.huabo.system.oracle.entity.TblIndicator;
import com.huabo.system.oracle.entity.TblIndicatorthreshold;
import com.huabo.system.oracle.entity.TblIndustryInner;
import com.huabo.system.oracle.entity.TblInnerrule;
import com.huabo.system.oracle.entity.TblInteriorExpert;
import com.huabo.system.oracle.entity.TblJob;
import com.huabo.system.oracle.entity.TblLoginType;
import com.huabo.system.oracle.entity.TblManageRight;
import com.huabo.system.oracle.entity.TblManageUserBook;
import com.huabo.system.oracle.entity.TblManageUserRight;
import com.huabo.system.oracle.entity.TblMonitorIndicatorresult;
import com.huabo.system.oracle.entity.TblMonitorModel;
import com.huabo.system.oracle.entity.TblMonitorRule;
import com.huabo.system.oracle.entity.TblMonitorSolution;
import com.huabo.system.oracle.entity.TblMonitorSolutionresult;
import com.huabo.system.oracle.entity.TblMyTask;
import com.huabo.system.oracle.entity.TblNbsjAuditplan;
import com.huabo.system.oracle.entity.TblNbsjPlanproject;
import com.huabo.system.oracle.entity.TblNbsjProject;
import com.huabo.system.oracle.entity.TblNbsjSheet;
import com.huabo.system.oracle.entity.TblNbsjSheetReport;
import com.huabo.system.oracle.entity.TblOrgNo;
import com.huabo.system.oracle.entity.TblOrgRight;
import com.huabo.system.oracle.entity.TblOrgRightnew;
import com.huabo.system.oracle.entity.TblOrganization;
import com.huabo.system.oracle.entity.TblOuterrule;
import com.huabo.system.oracle.entity.TblProcessAnalysis;
import com.huabo.system.oracle.entity.TblRisk;
import com.huabo.system.oracle.entity.TblRiskFlow;
import com.huabo.system.oracle.entity.TblRiskcategory;
import com.huabo.system.oracle.entity.TblRiskevent;
import com.huabo.system.oracle.entity.TblRole;
import com.huabo.system.oracle.entity.TblStaff;
import com.huabo.system.oracle.entity.TblSystemModule;
import com.huabo.system.oracle.entity.TblVersion;
import com.huabo.system.oracle.entity.TblVideoType;
import com.huabo.system.oracle.entity.TblYyUserOrder;
import com.huabo.system.oracle.entity.TblYyUserQuery;
import com.huabo.system.oracle.mapper.TblMyTaskMapper;
import com.huabo.system.oracle.vo.CopyVo;
import com.huabo.system.oracle.vo.TblFlowVo;
import com.huabo.system.page.PageBean;
import com.huabo.system.service.ProcessSettingService;
import com.huabo.system.service.TblAccBookService;
import com.huabo.system.service.TblAcctBookService;
import com.huabo.system.service.TblAcquisitionRecordService;
import com.huabo.system.service.TblAssessStaffService;
import com.huabo.system.service.TblAssessTargetService;
import com.huabo.system.service.TblAttachmentService;
import com.huabo.system.service.TblAuditOptionService;
import com.huabo.system.service.TblAutonoNumberService;
import com.huabo.system.service.TblBiChartService;
import com.huabo.system.service.TblBiCkEchartsService;
import com.huabo.system.service.TblBiReportMenuService;
import com.huabo.system.service.TblCirculationService;
import com.huabo.system.service.TblContractTypeofService;
import com.huabo.system.service.TblControlmatrixService;
import com.huabo.system.service.TblCourseService;
import com.huabo.system.service.TblExternalExpertService;
import com.huabo.system.service.TblFinanceDataService;
import com.huabo.system.service.TblFlowBussinessService;
import com.huabo.system.service.TblFlowIOuterruleService;
import com.huabo.system.service.TblFlowInnerRuleService;
import com.huabo.system.service.TblFlowService;
import com.huabo.system.service.TblFlowdesService;
import com.huabo.system.service.TblHomePageModelService;
import com.huabo.system.service.TblImplogService;
import com.huabo.system.service.TblIndicatorService;
import com.huabo.system.service.TblIndicatorthresholdService;
import com.huabo.system.service.TblIndustryInnerService;
import com.huabo.system.service.TblInteriorExpertService;
import com.huabo.system.service.TblJobService;
import com.huabo.system.service.TblLoginTypeService;
import com.huabo.system.service.TblManageRightService;
import com.huabo.system.service.TblManageScreenRightService;
import com.huabo.system.service.TblManageUserBookservice;
import com.huabo.system.service.TblMonitorIndicatorresultService;
import com.huabo.system.service.TblMonitorModelService;
import com.huabo.system.service.TblMonitorRuleService;
import com.huabo.system.service.TblMonitorSolutionService;
import com.huabo.system.service.TblMonitorSolutionresultService;
import com.huabo.system.service.TblNbsjAuditplanService;
import com.huabo.system.service.TblNbsjPlanprojectService;
import com.huabo.system.service.TblNbsjProjectService;
import com.huabo.system.service.TblNbsjSheetReportService;
import com.huabo.system.service.TblNbsjSheetService;
import com.huabo.system.service.TblOrgExcelService;
import com.huabo.system.service.TblOrgRightService;
import com.huabo.system.service.TblOrganizaService;
import com.huabo.system.service.TblProcessAnalysisService;
import com.huabo.system.service.TblRiskService;
import com.huabo.system.service.TblRiskcategoryService;
import com.huabo.system.service.TblRiskeventService;
import com.huabo.system.service.TblRoleService;
import com.huabo.system.service.TblStaffService;
import com.huabo.system.service.TblSystemModuleService;
import com.huabo.system.service.TblVersionService;
import com.huabo.system.service.TblVideoTypeService;
import com.huabo.system.service.TblYyOrgDepositService;
import com.huabo.system.service.TblYyUserOrderService;
import com.huabo.system.service.TblYyUserQueryService;
import com.huabo.system.service.TblyypriceService;
import com.huabo.system.service.TreeService;
import com.huabo.system.service.UserService;
import com.huabo.system.utils.DepartmentUtils;
import com.huabo.system.utils.ExcelUtil;
import com.huabo.system.utils.HttpClient;
import com.huabo.system.utils.MD5Encrypt;
import com.huabo.system.utils.RedisFinalUtis;
import com.huabo.system.utils.RightCatch;
import com.huabo.system.utils.TblAnalysisXml;
import com.huabo.system.utils.Tree;

import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import redis.clients.jedis.Jedis;

@RestController
@Slf4j
@Api(value = "设置Controller", tags = {"设置所有接口"})
public class TblOrganizationController extends BaseController implements ServletConfigAware {

    private static final Logger logger = LoggerFactory.getLogger(TblOrganizationController.class);
    private static final String separator = System.getProperty("file.separator");
    private static final String GROUP_STRUCTURE = PropertyFileReader.getItem("group.structure");
    private static final String acurl = ResourceBundle.getBundle("setting/process").getString("acurl").toString();
    private static final String filepath = getResourceBasePath() + "/src/main/resources/static";
    @Resource
    private HttpServletRequest request;

    @Resource
    private PageBean pageBean;

    @Resource
    private TblLoginTypeService tblLoginTypeService;

    @Resource
    private TblVideoTypeService tblVideoTypeService;

    @Resource
    private TreeService treeService;

    @Resource
    private RedisOrgController redisOrgController;

    @Resource
    private TblStaffService tblStaffService;

    @Resource
    private TblManageRightService tblManageRightService;

    @Resource
    private TblAutonoNumberService tblAutonoNumberService;

    @Resource
    private TblCourseService courseService;

    @Resource
    private TblIndustryInnerService tblIndustryInnerService;

    @Resource
    private TblYyOrgDepositService tblYyOrgDepositService;

    @Resource
    private TblYyUserOrderService tblYyUserOrderService;

    @Resource
    private TblyypriceService tblyypriceService;

    @Resource
    private TblRoleService tblRoleService;

    @Resource
    private TblJobService tblJobService;

    @Resource
    public TblAcctBookService tblAcctBookService;
    @Resource
    private TblFinanceDataService tblFinanceDataService;

    @Resource
    private TblInteriorExpertService tblInteriorExpertService;

    @Resource
    private TblExternalExpertService tblExternalExpertService;

    @Resource
    private TblYyUserQueryService tblYyUserQueryService;

    @Resource
    private TblAccBookService tblAccBookService;

    @Resource
    private TblAcquisitionRecordService tblAcquisitionRecordService;
    @Resource
    private TblMonitorSolutionresultService tblMonitorSolutionresultService;
    @Resource
    private TblNbsjAuditplanService tblNbsjAuditplanService;
    @Resource
    private TblAuditOptionService tblAuditOptionService;

    @Resource
    private TblProcessAnalysisService tblProcessAnalysisService;
    @Resource
    private TblMyTaskMapper tblMyTaskMapper;

    @Resource
    private TblMyTaskMySqlMapper tblMyTaskMySqlMapper;


//    @Value("${acurl}")
//    private String acurl;

    @Value("${formurl}")
    private String formurl;

    @Value("redisurl")
    private String redisurl;

    @Value("${activitiModelerUrl}")
    private String activitiModelerUrl;

    @Value("${getOrgChildrenUrl}")
    private String getOrgChildrenUrl;


    @Resource
    public TblImplogService tblImplogService;

    @Resource
    private TblSystemModuleService tblSystemModuleService;

    @Resource
    private TblBiReportMenuService tblBiReportMenuService;

    @Resource
    private TblBiCkEchartsService tblBiCkEchartsService;

    @Resource
    private TblBiChartService tblBiChartService;

    @Resource
    private TblFlowService tblFlowService;

    @Resource
    public TblOrganizaService tblOrganizaService;

    @Resource
    private UserService userService;

    @Resource
    private TblManageScreenRightService tblManageScreenRightService;

    @Resource
    private TblFlowdesService tblFlowdesService;

    @Resource
    private TblFlowBussinessService tblFlowBussinessService;

    @Resource
    private TblRiskeventService tblRiskeventService;

    @Resource
    private TblFlowInnerRuleService tblFlowInnerRuleService;
    @Resource
    private TblContractTypeofService tblContractTypeofService;

    @Resource
    private ProcessSettingService processSettingService;

    @Resource
    private TblFlowIOuterruleService flowIOuterruleService;

    @Resource
    private TblRiskService tblRiskService;

    @Resource
    public TblOrgRightService tblOrgRightService;

    @Resource
    private TblVersionService tblVersionService;

    @Resource
    private TblOrgExcelService tblOrgExcelService;
    @Resource
    private FileManager fileManager;

    @Resource
    private TblManageUserBookservice tblManageUserBookservice;

    @Resource
    public TblRiskcategoryService tblRiskcategoryService;
    @Resource
    private TblHomePageModelService tblHomePageModelService;
    @Resource
    private TblCirculationService tblCirculationService;
    @Resource
    private TblIndicatorService tblIndicatorService;
    @Resource
    private TblMonitorRuleService tblMonitorRuleService;
    @Resource
    private TblMonitorSolutionService tblMonitorSolutionService;
    @Resource
    private TblIndicatorthresholdService tblIndicatorthresholdService;
    @Resource
    private TblMonitorIndicatorresultService tblMonitorIndicatorresultService;
    @Resource
    private TblMonitorModelService tblMonitorModelService;
    @Resource
    private TblNbsjPlanprojectService TblNbsjPlanprojectService;
    @Resource
    private TblAttachmentService tblAttachmentService;
    @Resource
    private RepositoryService repositoryService;
    @Resource
    private HistoryService historyService;
    //    @Resource
//    private ProcessEngineFactoryBean processEngine;
    @Resource
    private ProcessEngineConfiguration processEngineConfiguration;
    @Resource
    private TblNbsjSheetService tblNbsjSheetService;
    @Resource
    private TblNbsjSheetReportService tblNbsjSheetReportService;
    @Resource
    private TblNbsjProjectService tblNbsjProjectService;
    @Resource
    private TblAssessTargetService tblAssessTargetService;
    @Resource
    private TblAssessStaffService tblAssessStaffService;
    @Resource
    private TblControlmatrixService tblControlmatrixService;

    public static final Integer DEL_YES = 1;
    public static final Integer DEL_NO = 0;


    /**
     * 我的待办
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/wddb/project_plan_list", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String project_plan_listdp(HttpServletRequest request,
                               @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                               @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) throws Exception {

        String result = null;
        Map<String, Object> resultMap = new HashMap<>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal orgid = staff.getCurrentOrg().getOrgid();
        BigDecimal staffid = staff.getStaffid();
        PageInfo<TblCirculation> pageInfo = new PageInfo<>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);
        logger.info("我的代办=======");
        try {
            pageInfo = processSettingService.todoList(staff, pageNumber, pageSize, staff.getCurrentOrg().getOrgname());
            List<TblCirculation> tlist = pageInfo.getTlist();
            if (tlist.size() > 0) {
                for (TblCirculation tblCirculation : tlist) {
                    logger.info("我的代办===名称====" + tblCirculation.getCyname());
                    System.out.println("我的代办===名称====" + tblCirculation.getCyname());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            JsonBean.error();
        }
        resultMap.put("code", 1);
        resultMap.put("msg", "访问接口成功");
        resultMap.put("data", pageInfo);
        JSONObject jsonObjectMV = new JSONObject(resultMap);
        result = jsonObjectMV.toString();
        return result;
    }

    /**
     * 我的待办--实际使用
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/wddb/project_plan", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "我的待办")
    public @ResponseBody
    String project_plan(HttpServletRequest request,
                        @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                        @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {

        String result = null;
        try {
            Map<String, Object> resultMap = processSettingService.toList(token, pageNumber, pageSize);
            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
        } catch (Exception e) {
            e.printStackTrace();
            JsonBean.error();
        }
        return result;
    }


    /**
     * 审计 工作底稿--审批
     *
     * @Author: TYB
     * @Date: 2017-03-06 下午 5:02
     * @Des: 审计 工作底稿--审批
     */
    @RequestMapping(value = "/sjss/to_sp_dggl", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String to_sp_dggl(HttpServletRequest request,
                             @RequestParam(value = "spid", required = false) BigDecimal spid,
                             @RequestParam(value = "tid", required = false) String tid,
                             @RequestParam(value = "cyid", required = false) String cyid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                TblNbsjSheet sheet = this.tblNbsjSheetService.get(spid);
                if (StringUtils.isNotBlank(tid) && sheet.getState() != TblNbsjSheet.STATE5) {
                    List<String> btnList = processSettingService.getButtonsForTransition(tid);
                    resultMap.put("btnList", btnList);
                }
                if (StringUtils.isNotBlank(cyid)) {
                    TblCirculation cy = tblCirculationService.get(cyid);
                    resultMap.put("cy", cy);
                }
                List<TblAuditOption> ao = tblAuditOptionService.findOptionByRelation(sheet.getSheetid().toString(), Integer.parseInt(cyid));
                resultMap.put("sheet", sheet);
                resultMap.put("ao", ao);
                resultMap.put("tid", tid);
                resultMap.put("v", request.getParameter("v"));
                List<TblAttachment> fj = tblAttachmentService.findAllByTblNBSJSheet(spid.toString());
                List<TblNbsjSheetReport> tnsrList = tblNbsjSheetReportService.findReportListBySheet(spid.toString());
                TblNbsjProject project = tblNbsjProjectService.findBySheetid(spid);
                resultMap.put("project", project);
                resultMap.put("tnsrList", tnsrList);
                resultMap.put("fj", fj);
                resultMap.put("spid", spid);
            } catch (Exception e) {
                e.printStackTrace();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            try {
                TblNbsjSheetMySql sheet = this.tblNbsjSheetService.getMySql(spid);
                if (StringUtils.isNotBlank(tid) && sheet.getState() != TblNbsjSheet.STATE5) {
                    List<String> btnList = processSettingService.getButtonsForTransition(tid);
                    resultMap.put("btnList", btnList);
                }
                if (StringUtils.isNotBlank(cyid)) {
                    TblCirculationMySql cy = tblCirculationService.getMySql(cyid);
                    resultMap.put("cy", cy);
                }
                List<TblAuditOptionMySql> ao = tblAuditOptionService.findOptionByMySqlRelation(sheet.getSheetid().toString(), Integer.parseInt(cyid));
                resultMap.put("sheet", sheet);
                resultMap.put("ao", ao);
                resultMap.put("tid", tid);
                resultMap.put("v", request.getParameter("v"));
                List<TblAttachment> fj = tblAttachmentService.findAllByTblNBSJSheet(spid.toString());
                List<TblNbsjSheetReportMySql> tnsrList = tblNbsjSheetReportService.findReportListByMySqlSheet(spid.toString());
                TblNbsjProjectMySql project = tblNbsjProjectService.findByMySqlSheetid(spid);
                resultMap.put("project", project);
                resultMap.put("tnsrList", tnsrList);
                resultMap.put("fj", fj);
                resultMap.put("spid", spid);
            } catch (Exception e) {
                e.printStackTrace();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    /**
     * 跟踪流程图
     *
     * @Author: TYB
     * @Date: 2016-12-16 下午 5:43
     * @Des: 跟踪流程图
     */
    @RequestMapping(value = "/gz_lct", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String gz_lct(HttpServletRequest request,
                         @RequestParam(value = "businesskey", required = false) String businesskey,
                         @RequestParam(value = "cyid", required = false) String cyid) {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        logger.info("跟踪流程图");
        if (!StringUtil.isNullOrEmpty(cyid)) {
            TblCirculation cy = tblCirculationService.get(cyid);
            resultMap.put("cy", cy);
//        if(cy.getDefinitionid().equals("cyhw_jjhtjc")){
            resultMap.put("url", HttpClient.jkurl + cy.getBusinesskey());
//        }
        } else if (!StringUtil.isNullOrEmpty(businesskey)) {
            resultMap.put("url", HttpClient.jkurl + businesskey);
        }
        //  resultMap.put("/nbsj/sjgl/gz_lct");
        resultMap.put("code", "1");
        resultMap.put("msg", "数据访问成功");
        JSONObject jsonObjectMV = new JSONObject(resultMap);
        result = jsonObjectMV.toString();
        return result;
    }

    /**
     * 我的评价
     * 我的评价
     *
     * @return
     */

    @RequestMapping(value = "/wdpj/t08_mygrade_list", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String t08_mygrade_list(
            @RequestParam(value = "assid", required = false) String assid,
            @RequestParam(value = "assName", required = false) String assName, HttpServletRequest request,
            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) throws Exception {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal staffid = staff.getStaffid();

        PageInfo<TblAssessTarget> pageInfo = new PageInfo<TblAssessTarget>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);

        this.tblAssessTargetService.MyMark(staffid, assid, assName, pageInfo);

        @SuppressWarnings("unchecked")
        List<TblAssessTarget> list2 = pageInfo.getTlist();
        for (TblAssessTarget tar : list2) {
            String status = this.tblAssessStaffService.getStatusByUserAsss(staffid, tar.getAssid(), tar.getOrgid());
            tar.setStatus(status);
            Map<String, String> map = new HashMap<>();
            resultMap.put("pageInfo", pageInfo);
            resultMap.put("status", tar.getStatus());
            resultMap.put("assessname", tar.getAssessname());
            resultMap.put("orgName", tar.getOrgname());

            // list.add(map);
        }
        //pageBean.setRecordList(list);
        JSONObject jsonObjectMV = new JSONObject(resultMap);
        result = jsonObjectMV.toString();
        return result;
    }


    /**
     * 我的预警-规则详情
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/wdts/resultmgmtgz", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String resultmgmtgz(@RequestParam(value = "pageNumber", required = true, defaultValue = "1") Integer pageNumber,
                               @RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize,
                               @RequestParam(value = "solutionid", required = false) String solutionid,
                               HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);

        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            PageInfo<TblMonitorRule> pageInfo = new PageInfo<TblMonitorRule>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            this.tblMonitorRuleService.findAll(solutionid, pageInfo);
            // mv = new ModelAndView("znjk/gzjk/rule/gz_rulesmgmt");
            TblMonitorSolution solution = tblMonitorSolutionService.findOne(solutionid);
            List<String[]> strs = new ArrayList<String[]>();
            PageInfo<TblMonitorSolutionresult> pageIn = new PageInfo<TblMonitorSolutionresult>();
            pageIn.setCurrentPage(pageNumber);
            pageIn.setPageSize(pageSize);
            if (pageInfo.getTlist() != null && pageInfo.getTotalRecord() > 0) {
                List<TblMonitorRule> list = pageBean.getRecordList();
                for (TblMonitorRule tblMonitorRule : list) {
                    String[] str = new String[2];
                    str[0] = tblMonitorRule.getRuleid().toString();
                    //TblAccBook acctbook = this.tblAccBookService.findAllById(new BigDecimal(tblMonitorRule.getConnectionstrings()));
                    TblAccBook acctbook = tblAccBookService.findByBookIdOne(tblMonitorRule.getConnectionstrings());
                    resultMap = tblMonitorSolutionresultService.findBySoultionIdZK("ZNJK_GZ_" + tblMonitorRule.getRuleid().toString(),
                            new BigDecimal(solutionid), tblMonitorRule.getRuleid().toString(), acctbook.getAcctid(), pageIn);
                    if (pageInfo.getTlist() != null && pageInfo.getTotalRecord() > 0) {
                        str[1] = "1";
                    } else {
                        str[1] = "2";
                    }
                    strs.add(str);
                }

            }
            resultMap.put("strs", strs);
            resultMap.put("solution", solution);
            resultMap.put("pageBean", pageBean);
            resultMap.put("solutionid", solutionid);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            PageInfo<TblMonitorRuleMySql> pageInfo = new PageInfo<>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            this.tblMonitorRuleService.findAllMySql(solutionid, pageInfo);
            // mv = new ModelAndView("znjk/gzjk/rule/gz_rulesmgmt");
            TblMonitorSolutionMySql solution = tblMonitorSolutionService.findMySqlOne(solutionid);
            List<String[]> strs = new ArrayList<String[]>();

            PageInfo<TblMonitorSolutionresultMySql> pageIn = new PageInfo<>();
            pageIn.setCurrentPage(pageNumber);
            pageIn.setPageSize(pageSize);
            if (pageInfo.getTlist() != null && pageInfo.getTotalRecord() > 0) {
                List<TblMonitorRuleMySql> list = pageBean.getRecordList();
                for (TblMonitorRuleMySql tblMonitorRule : list) {
                    String[] str = new String[2];
                    str[0] = tblMonitorRule.getRuleid().toString();
                    //TblAccBook acctbook = this.tblAccBookService.findAllById(new BigDecimal(tblMonitorRule.getConnectionstrings()));
                    TblAccBookMySql acctbook = tblAccBookService.findByMySqlBookIdOne(tblMonitorRule.getConnectionstrings());
                    resultMap = tblMonitorSolutionresultService.findByMySqlSoultionIdZK("ZNJK_GZ_" + tblMonitorRule.getRuleid().toString(),
                            new BigDecimal(solutionid), tblMonitorRule.getRuleid().toString(), acctbook.getAcctid(), pageIn);
                    if (pageInfo.getTlist() != null && pageInfo.getTotalRecord() > 0) {
                        str[1] = "1";
                    } else {
                        str[1] = "2";
                    }
                    strs.add(str);
                }

            }
            resultMap.put("strs", strs);
            resultMap.put("solution", solution);
            resultMap.put("pageBean", pageBean);
            resultMap.put("solutionid", solutionid);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }


    /**
     * /sy/findnum
     *
     * @param request
     * @param token
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/sy/findnum", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String addPjgl(HttpServletRequest request,
                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                   @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                   @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) throws Exception {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal orgid = staff.getCurrentOrg().getOrgid();
        BigDecimal staffid = staff.getStaffid();
        Integer count = 0;


        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            PageInfo<ProcessSetting> pageInfo = new PageInfo<ProcessSetting>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            try {
                PageInfo page = processSettingService.todoList(pageInfo, staff, orgid, staffid);

                List<TblCirculation> cirs = tblCirculationService.findStaffid("");
                List<TblMyTask> list = null;
                if (staffid != null && staff.getUsername() != null) {
                    list = HttpClient.findByTask(staff.getUsername(), staffid.toString(), 1, 100);
                } else {
                    list = HttpClient.findByTask("", staffid.toString(), 1, 100);
                }

                List<TblMyTask> tj = tblMyTaskMapper.findByObj("", "审查", staff.getStaffid().toString(), "法务");
                List<TblMyTask> tj2 = tblMyTaskMapper.findByObj("", "审查", staff.getStaffid().toString(), "财务");
                System.out.println("======================================================================");
                list.addAll(tj);
                list.addAll(tj2);

                List<TblCirculation> circulations = new ArrayList<>();
                if (list != null && list.size() > 0) {
                    for (TblCirculation tblCirculation : cirs) {
                        //TblStaff staff = tblStaffService.findById(tblCirculation.getCyStaffid());
                        TblOrganization organization = null;
                        if (staff.getCurrentOrg() != null && staff.getCurrentOrg().getFatherorgid() != null) {
                            organization = tblOrganizaService.findById(staff.getCurrentOrg().getFatherorgid().toString());
                        }
                        if ((staff != null && staff.getCurrentOrg() != null && staff.getCurrentOrg().getFatherorgid().toString().equals(orgid))
                                || (staff != null && staff.getCurrentOrg() != null && orgid.equals(orgid))
                                || (organization != null && organization.getFatherorgid().toString().equals(orgid))
                                || (organization != null && organization.getOrgid().toString().equals(orgid))) {
                            for (TblMyTask myTask : list) {
                                if (myTask.getTaskId() == null && myTask.getFxexam().equals(staff.getStaffid().toString()) && tblCirculation.getTaskid().equals(myTask.getFromid())) {
                                    circulations.add(tblCirculation);
                                }
                                if (tblCirculation != null && myTask.getProcessInstanceId().equals(tblCirculation.getBusinesskey())) {
                                    circulations.add(tblCirculation);
                                }
                            }
                        }
                    }
                }
                // 删除ArrayList中重复元素，保持顺序
                Set<TblCirculation> set = new HashSet<TblCirculation>();
                List<TblCirculation> newList = new ArrayList<>();
                for (Iterator<TblCirculation> iter = circulations.iterator(); iter.hasNext(); ) {
                    TblCirculation element = (TblCirculation) iter.next();
                    if (set.add(element))
                        newList.add(element);
                }
                circulations.clear();
                count = pageInfo.getTotalRecord() + newList.size();
                count = pageInfo.getTotalRecord();
                return count.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            PageInfo<ProcessSettingMySql> pageInfo = new PageInfo<>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            try {

                PageInfo page = processSettingService.todoMySqlList(pageInfo, staff, orgid, staffid);

                List<TblCirculationMySql> cirs = tblCirculationService.findMyStaffid("");
                List<TblMyTaskMySql> list = null;
                if (staffid != null && staff.getUsername() != null) {
                    list = HttpClient.findByMySqlTask(staff.getUsername(), staffid.toString(), 1, 100);
                } else {
                    list = HttpClient.findByMySqlTask("", staffid.toString(), 1, 100);
                }

                List<TblMyTaskMySql> tj = tblMyTaskMySqlMapper.findByObj("", "审查", staff.getStaffid().toString(), "法务");
                List<TblMyTaskMySql> tj2 = tblMyTaskMySqlMapper.findByObj("", "审查", staff.getStaffid().toString(), "财务");
                System.out.println("======================================================================");
                list.addAll(tj);
                list.addAll(tj2);

                List<TblCirculationMySql> circulations = new ArrayList<>();
                if (list != null && list.size() > 0) {
                    for (TblCirculationMySql tblCirculation : cirs) {
                        //TblStaff staff = tblStaffService.findById(tblCirculation.getCyStaffid());
                        TblOrganizationMySql organization = null;
                        if (staff.getCurrentOrg() != null && staff.getCurrentOrg().getFatherorgid() != null) {
                            organization = tblOrganizaService.findByMySqlId(staff.getCurrentOrg().getFatherorgid().toString());
                        }
                        if ((staff != null && staff.getCurrentOrg() != null && staff.getCurrentOrg().getFatherorgid().toString().equals(orgid))
                                || (staff != null && staff.getCurrentOrg() != null && orgid.equals(orgid))
                                || (organization != null && organization.getFatherorgid().toString().equals(orgid))
                                || (organization != null && organization.getOrgid().toString().equals(orgid))) {
                            for (com.huabo.system.mysql.entity.TblMyTaskMySql myTask : list) {
                                if (myTask.getTaskId() == null && myTask.getFxexam().equals(staff.getStaffid().toString()) && tblCirculation.getTaskid().equals(myTask.getFromid())) {
                                    circulations.add(tblCirculation);
                                }
                                if (tblCirculation != null && myTask.getProcessInstanceId().equals(tblCirculation.getBusinesskey())) {
                                    circulations.add(tblCirculation);
                                }
                            }
                        }
                    }
                }
                // 删除ArrayList中重复元素，保持顺序
                Set<TblCirculationMySql> set = new HashSet<>();
                List<TblCirculationMySql> newList = new ArrayList<>();
                for (Iterator<TblCirculationMySql> iter = circulations.iterator(); iter.hasNext(); ) {
                    TblCirculationMySql element = (TblCirculationMySql) iter.next();
                    if (set.add(element))
                        newList.add(element);
                }
                circulations.clear();
                count = pageInfo.getTotalRecord() + newList.size();
                count = pageInfo.getTotalRecord();
                return count.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return count.toString();
    }

    /**
     * 判断是否有权限
     *
     * @return
     */
    @RequestMapping(value = "/jurisdiction", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String jurisdiction(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
                        @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        //Map<String,Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            PageInfo<TblHomePageModel> pageInfo = new PageInfo<TblHomePageModel>();
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal staffid = staff.getStaffid();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            Map<String, Object> resultMap = tblHomePageModelService.homePageModels(pageInfo, staffid);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
        } else {
            PageInfo<TblHomePageModelMySql> pageInfo = new PageInfo<>();
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal staffid = staff.getStaffid();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            Map<String, Object> resultMap = tblHomePageModelService.homePageModelsMySql(pageInfo, staffid);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
        }
        return result;
    }

    /**
     * 我的传阅
     *
     * @param request
     * @param pageNumber
     * @param find
     * @return
     */

    @RequestMapping(value = "/my_circulation", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "我的传阅")
    public @ResponseBody
    String my_circulation(HttpServletRequest request, Find find,
                          TblCirculation tca,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                          @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<>(0);
        PageInfo<TblCirculation> pageInfo = new PageInfo<TblCirculation>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);
        //TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal staffid = staff.getStaffid();
        resultMap = tblCirculationService.findAll(staffid, tca, pageInfo);

        JSONObject jsonObjectMV = new JSONObject(resultMap);
        result = jsonObjectMV.toString();
        return result;

    }

    /**
     * 指标预警
     */
    @RequestMapping(value = "/zb_list", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "指标预警")
    public @ResponseBody
    String zbyj_list(HttpServletRequest request,
                     @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                     @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {

        String result = null;
        // Map<String,Object> resultMap = new HashMap<String, Object>(0);
        PageInfo<TblIndicator> pageInfo = new PageInfo<TblIndicator>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal staffid = staff.getStaffid();
        Map<String, Object> resultMap = tblIndicatorService.findIndicatorByUseridAndSlouid(pageInfo, staffid);
//        for (int i = 0; i < indicator.size(); i++) {
//            Object[] object = indicator.get(i);
//            resultMap.put("INDICATORID", object[0].toString());
//            resultMap.put("INDICATORCODE", object[1].toString());
//            resultMap.put("INDICATORNAME", object[2].toString());
//            resultMap.put("MEMO", object[3]==null?"":object[3].toString());
//            resultMap.put("SOLUTIONID", object[4].toString());
//        }

        JSONObject jsonObjectMV = new JSONObject(resultMap);
        result = jsonObjectMV.toString();
        return result;

    }

    /**
     * /gz_list
     *
     * @param pageNumber
     * @param pageSize
     * @param token
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/gz_list", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String gzyj_list(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                     @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token, HttpServletRequest request) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            PageInfo<TblMonitorRule> pageInfo = new PageInfo<TblMonitorRule>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal staffid = staff.getStaffid();
            Map<String, Object> resultMap = tblMonitorRuleService.findTblMonitorRuleByUser(staffid, pageInfo);
            resultMap.put("data", pageInfo);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            PageInfo<TblMonitorRuleMySql> pageInfo = new PageInfo<TblMonitorRuleMySql>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal staffid = staff.getStaffid();
            Map<String, Object> resultMap = tblMonitorRuleService.findTblMonitorRuleByMySqlUser(staffid, pageInfo);
            resultMap.put("data", pageInfo);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    /**
     * 规则方案、指标方案、模型， 预警
     *
     * @param request
     * @param type
     * @return
     */
    @RequestMapping(value = "/wdts/yjfa", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String yjfa(HttpServletRequest request, @RequestParam(value = "type", required = true) String type,
                @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            PageInfo<TblMonitorSolution> pageInfo = new PageInfo<>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal staffid = staff.getStaffid();
            Map<String, Object> resultMap = tblMonitorSolutionService.tblMonitorSolutionService(staffid, pageInfo, type);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            PageInfo<TblMonitorSolutionMySql> pageInfo = new PageInfo<>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal staffid = staff.getStaffid();
            Map<String, Object> resultMap = tblMonitorSolutionService.tblMonitorSolutionMySqlService(staffid, pageInfo, type);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    /**
     * 我的预警-指标详情
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/wdts/resultmgmtzb", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String resultmgmtzb(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                        @RequestParam(value = "solutionid", required = true) String solutionid, HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        PageInfo<TblIndicator> pageInfo = new PageInfo<TblIndicator>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);
        resultMap = tblIndicatorService.findIndicatorByJKZX(solutionid, pageInfo);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblMonitorSolution solution = tblMonitorSolutionService.findOne(solutionid);
            resultMap.put("solution", solution);
        } else {
            TblMonitorSolutionMySql solutionMySql = tblMonitorSolutionService.findMySqlOne(solutionid);
            resultMap.put("solution", solutionMySql);
        }
//        mv = new ModelAndView("znjk/zbjk/kri_info_ts");

        //resultMap.put("pageBean", pageBean);
        resultMap.put("solutionid", solutionid);
        resultMap.put("data", pageInfo);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    /**
     * 指标管理-查看
     *
     * @param request
     * @return
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/zbjk/kri_info_disp", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "指标管理-查看")
    public String kri_info_disp(HttpServletRequest request, TblIndicator indicator,
                                @RequestParam(value = "flows", required = false) String flows) {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (indicator.getIndicatorid() != null && !"".equals(indicator.getIndicatorid())) {
                indicator = tblIndicatorService.findOne(indicator.getIndicatorid().toString());
                Set<TblFlow> fw = indicator.getTblIndicatorFlows();
                for (TblFlow tblFlow : fw) {
                    flows += tblFlow.getFlowid() + ",";
                }
            }
            TblStaff user = userService.findById(indicator.getStaffid().toString());
            resultMap.put("indicator", indicator);
            resultMap.put("flows", flows);
            resultMap.put("creater", user.getUsername());
        } else {
            TblIndicatorMySql indicatorMySql = new TblIndicatorMySql();
            BeanUtils.copyProperties(indicator, indicatorMySql);
            if (indicator.getIndicatorid() != null && !"".equals(indicator.getIndicatorid())) {
                indicatorMySql = tblIndicatorService.findMySqlOne(indicatorMySql.getIndicatorid().toString());
                Set<TblFlowMySql> fw = indicatorMySql.getTblIndicatorFlows();
                for (TblFlowMySql tblFlow : fw) {
                    flows += tblFlow.getFlowid() + ",";
                }
            }
            TblStaffMySql user = userService.findByMySqlId(indicatorMySql.getStaffid().toString());
            resultMap.put("indicator", indicatorMySql);
            resultMap.put("flows", flows);
            resultMap.put("creater", user.getUsername());
        }
        // ModelAndView mv = new ModelAndView();
        //  mv.setViewName("znjk/zbjk/kri_info_disp");

        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    /**
     * 指标管理-计算公式_查看
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/zbjk/kri_info_formula_disp", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "指标管理-计算公式_查看")
    public String kri_info_formula_disp(HttpServletRequest request,
                                        @RequestParam(value = "indicatorid", required = false) String indicatorid) {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblIndicator indicator = null;
        if (indicatorid != null && !"".equals(indicatorid)) {
            //TblIndicatorService service = (TblIndicatorService) SpringContextHolder.getBean("TblIndicatorService");
            indicator = tblIndicatorService.findOne(indicatorid);
        }
        // mv.setViewName("znjk/zbjk/kri_info_formula_disp");
        resultMap.put("indicatorid", indicatorid);
        resultMap.put("indicator", indicator);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    /**
     * 指标管理-指标基准阈值列表-查看
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/zbjk/kri_info_range_mng_disp", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "指标管理-指标基准阈值列表-查看")
    public String kri_info_range_mng_disp(HttpServletRequest request,
                                          @RequestParam(value = "thresholdid", required = true) String thresholdid,
                                          @RequestParam(value = "orgid", required = false) String orgid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        List<TblIndicatorthreshold> hold = tblIndicatorthresholdService.findByIndicatorId(thresholdid);
        // mv.setViewName("znjk/zbjk/kri_info_range_mng_disp");
        resultMap.put("thresholdid", thresholdid);
        resultMap.put("hold", hold);
        resultMap.put("orgId", orgid);
        resultMap.put("tableHistoryRows", hold.size());
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    /**
     * 我的预警-查看指标执行结果
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/wdts/kri_info_result", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String wdts_kri_info_reult(@RequestParam(value = "pageNumber", required = true, defaultValue = "1") Integer pageNumber,
                                      @RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "indicatorid", required = true) BigDecimal indicatorid,
                                      @RequestParam(value = "solutionresultid", required = true) BigDecimal solutionresultid,
                                      @RequestParam(value = "type", required = false) String type,
                                      HttpServletRequest request) {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        // mv.setViewName("znjk/result/kri_info_result_ts");

        PageInfo<TblMonitorIndicatorresult> pageInfo = new PageInfo<TblMonitorIndicatorresult>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);
        // 指标方案
        resultMap = this.tblMonitorIndicatorresultService.getResultListJKZX(pageInfo, indicatorid, solutionresultid);
        resultMap.put("indicatorid", indicatorid);
        resultMap.put("solutionresultid", solutionresultid);
        resultMap.put("type", type);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    /**
     * 我的预警-模型详情
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/wdts/resultmgmtmx", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String resultmgmtmx(@RequestParam(value = "pageNumber", required = true, defaultValue = "1") Integer pageNumber,
                               @RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize,
                               @RequestParam(value = "solutionid", required = true) String solutionid, HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);

        PageInfo<TblMonitorModel> pageInfo = new PageInfo<TblMonitorModel>();
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setPageSize(pageSize);
        resultMap = tblMonitorModelService.findByModelJKZX(solutionid, pageInfo);
        // mv = new ModelAndView("znjk/mxjk/modelmgmt_ts");
        resultMap.put("solutionid", solutionid);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    /**
     * /gzjk/rule/rule_disp
     *
     * @param request
     * @param ruleid
     * @return
     */
    @RequestMapping(value = "/gzjk/rule/rule_disp", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String torule_disp(HttpServletRequest request,
                              @RequestParam(value = "ruleid", required = true) BigDecimal ruleid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblMonitorRule rule = tblMonitorRuleService.findOne(ruleid);
        if (rule != null) {
            if (rule.getOrgid() != null && rule.getOrgid() != null) {
                if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
                    TblOrganization o = tblOrganizaService.findByoId(rule.getOrgid());
                    resultMap.put("org", o);
                } else {
                    TblOrganizationMySql o = tblOrganizaService.findByMySqloId(rule.getOrgid());
                    resultMap.put("org", o);
                }
            }
            resultMap.put("rule", rule);
        }
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    /**
     * 我的预警-查看规则执行结果
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/wdts/resultmgmt", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String resultmgmtgzxq(@RequestParam(value = "pageNumber", required = true, defaultValue = "1") Integer pageNumber,
                                 @RequestParam(value = "pageSize", required = true, defaultValue = "10") Integer pageSize,
                                 @RequestParam(value = "solutionid", required = false) String solutionid,
                                 @RequestParam(value = "type", required = false) String type,
                                 @RequestParam(value = "ruleid", required = false) BigDecimal ruleid,
                                 HttpServletRequest request) {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (ruleid != null && ruleid.toString().length() > 0) {
            if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
                PageInfo<TblMonitorSolutionresult> pageInfo = new PageInfo<TblMonitorSolutionresult>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                TblMonitorRule rule = this.tblMonitorRuleService.findOne(ruleid);
                TblAccBook acctbook = tblAccBookService.findByBookIdOne(rule.getConnectionstrings());
                List<String> list = tblMonitorSolutionresultService.find("ZNJK_GZ_" + ruleid, new BigDecimal(solutionid),
                        ruleid.toString(), acctbook.getAcctid());
                resultMap.put("list", list);
                resultMap.put("length", list.size() - 1);
                resultMap = tblMonitorSolutionresultService.findBySoultionIdZKZX("ZNJK_GZ_" + ruleid,
                        new BigDecimal(solutionid), ruleid.toString(), acctbook.getAcctid(), pageInfo);
            } else {
                PageInfo<TblMonitorSolutionresultMySql> pageInfo = new PageInfo<>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                TblMonitorRuleMySql rule = this.tblMonitorRuleService.findMySqlOne(ruleid);
                TblAccBookMySql acctbook = tblAccBookService.findByMySqlBookIdOne(rule.getConnectionstrings());
                List<String> list = tblMonitorSolutionresultService.find("ZNJK_GZ_" + ruleid, new BigDecimal(solutionid),
                        ruleid.toString(), acctbook.getAcctid());
                resultMap.put("list", list);
                resultMap.put("length", list.size() - 1);
                resultMap = tblMonitorSolutionresultService.findByMySqlSoultionIdZKZX("ZNJK_GZ_" + ruleid,
                        new BigDecimal(solutionid), ruleid.toString(), acctbook.getAcctid(), pageInfo);
            }
        }
        resultMap.put("solutionid", solutionid);
        resultMap.put("ruleid", ruleid);
        resultMap.put("type", type);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    /**
     * @Author: TYB
     * @Date: 2016-12-02 下午 3:13
     * @Des:审批计划详情页
     */
    @RequestMapping(value = "/jhgl/to_tjspPlan_info", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String to_tjspPlan_info(HttpServletRequest request,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                   @RequestParam(value = "planid", required = false) String planid,
                                   @RequestParam(value = "tid", required = false) String tid,
                                   @RequestParam(value = "cyid", required = false) String cyid) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal staffid = staff.getStaffid();
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (planid != null && planid.length() > 0) {
                TblNbsjAuditplan plan = tblNbsjAuditplanService.get(planid);
                resultMap.put("plan", plan);
            }
            resultMap.put("t", request.getParameter("t"));

            TblNbsjAuditplan form = tblNbsjAuditplanService.get(planid);
            if (form != null) {
                List<TblAuditOption> ao = tblAuditOptionService.findOptionByRelationId(form.getPlanid());
                List<TblNbsjAuditplan> list = tblNbsjAuditplanService.findCheckJH(planid);
                //TblAttachment att = form.getTblplanAtts();
                TblAttachment att = tblAttachmentService.selectAtt(form.getAttid());
                TblStaff user = userService.findById(form.getStaffid().toString());
                if (StringUtils.isNotBlank(tid)) {
                    form.getOpinionstatus().toString();
                    List<String> btnList = processSettingService.getButtonsForTransition(tid);
                    resultMap.put("btnList", btnList);
                }
                resultMap.put("ao", ao);
                resultMap.put("v", request.getParameter("v"));
                resultMap.put("tId", tid);
                resultMap.put("logUser", user);
                resultMap.put("list", list);
                resultMap.put("form", form);
                resultMap.put("att", att);
                //	List<TblAuditOption> ao = tblAuditOptionService.findOptionByRelationId(form.getPlanid().toString(),Integer.parseInt(cyId));
                if (StringUtils.isNotBlank(cyid)) {
                    TblCirculation cy = tblCirculationService.get(cyid);
                    resultMap.put("cy", cy);
                }
                //	mv.addObject("ao",ao);
                //修改
                List<TblNbsjPlanproject> findByPlanId = TblNbsjPlanprojectService.findByPlanId(planid);//计划项目
                resultMap.put("findByPlanId", findByPlanId);
                resultMap.put("projectsize", findByPlanId.size());
//            resultMap.put("nbsj/sjgl/to_tjspPlan_info");
//            if(form.getOpinionStatus()==form.SPTZ && form.getTblcreater().getStaffid().equals(staffid)) {
//                resultMap.put("nbsj/sjgl/audit_plan_add");
//            }
                //mv.setViewName("/nbsj/sjgl/to_tjspinfo");
            }
        } else {
            if (planid != null && planid.length() > 0) {
                TblNbsjAuditplanMySql plan = tblNbsjAuditplanService.getMySql(planid);
                resultMap.put("plan", plan);
            }
            resultMap.put("t", request.getParameter("t"));

            TblNbsjAuditplanMySql form = tblNbsjAuditplanService.getMySql(planid);
            if (form != null) {
                List<TblAuditOptionMySql> ao = tblAuditOptionService.findOptionByMySqlRelationId(form.getPlanid());
                List<TblNbsjAuditplanMySql> list = tblNbsjAuditplanService.findMySqlCheckJH(planid);
                //TblAttachment att = form.getTblplanAtts();
                TblAttachment att = tblAttachmentService.selectAtt(form.getAttid());
                TblStaffMySql user = userService.findByMySqlId(form.getStaffid().toString());
                if (StringUtils.isNotBlank(tid)) {
                    form.getOpinionstatus().toString();
                    List<String> btnList = processSettingService.getButtonsForTransition(tid);
                    resultMap.put("btnList", btnList);
                }
                resultMap.put("ao", ao);
                resultMap.put("v", request.getParameter("v"));
                resultMap.put("tId", tid);
                resultMap.put("logUser", user);
                resultMap.put("list", list);
                resultMap.put("form", form);
                resultMap.put("att", att);
                //	List<TblAuditOption> ao = tblAuditOptionService.findOptionByRelationId(form.getPlanid().toString(),Integer.parseInt(cyId));
                if (StringUtils.isNotBlank(cyid)) {
                    TblCirculationMySql cy = tblCirculationService.getMySql(cyid);
                    resultMap.put("cy", cy);
                }
                //	mv.addObject("ao",ao);
                //修改
                List<TblNbsjPlanprojectMySql> findByPlanId = TblNbsjPlanprojectService.findByMySqlPlanId(planid);//计划项目
                resultMap.put("findByPlanId", findByPlanId);
                resultMap.put("projectsize", findByPlanId.size());
            }
        }
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    @RequestMapping(value = "/org/add", method = {RequestMethod.POST})
    @ApiOperation(value = "公司管理-新建前查询")
    public String orgAdd(HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String pid = request.getParameter("pid");

        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Integer orderid = (Integer) tblOrganizaService.countOrg();
            if (pid == null) {
                resultMap = (Map<String, Object>) new ModelAndView("code", HttpStatus.valueOf("1"));
            } else {
                TblOrganization org = tblOrganizaService.findById(pid);
                resultMap = (Map<String, Object>) new ModelAndView("code", HttpStatus.valueOf("1"));
                JSONObject orgObject = new JSONObject((Map<String, Object>) org);
            }
        } else {
            Integer orderid = (Integer) tblOrganizaService.countOrg();
            if (pid == null) {
                resultMap = (Map<String, Object>) new ModelAndView("code", HttpStatus.valueOf("1"));
            } else {
                TblOrganizationMySql org = tblOrganizaService.findByMySqlId(pid);
                resultMap = (Map<String, Object>) new ModelAndView("code", HttpStatus.valueOf("1"));
                JSONObject orgObject = new JSONObject((Map<String, Object>) org);
            }
        }
        JSONObject jsonObject = new JSONObject(resultMap);
        result = jsonObject.toString();
        return result;
    }


    @RequestMapping(value = "/redisorg/findOrganizationByJTTreeAllGS", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "公司管理-列表-左侧列表")
    public @ResponseBody
    String redisorgFindOrganizationByJTTreeAllGS(@RequestParam(value = "nodeId", required = false) BigDecimal nodeId,
                                                 String type, HttpServletRequest request,
                                                 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        if (null == nodeId) {
            //TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            nodeId = staff.getCurrentOrg().getOrgid();
        }
        String str;
        HashMap<String, Object> fields = new HashMap<String, Object>();
        fields.put("nodeId", nodeId);
        // List<Tree> list = this.tblOrganizaService.getNodeAll(nodeId);
        // json = JSONObject.toJSONString(list);
        if (StringUtils.isNotBlank(type)) {
            try {
                str = HttpClient.request(HttpClient.getOrgChildrenUrl, fields, null);
                if (!StringUtils.isNotBlank(str)) {
                    List<Tree> list = this.tblOrganizaService.getJTTreeNodeId(nodeId);
                    str = JSONObject.toJSONString(list);
                }
                return str;
            } catch (Exception e) {
                List<Tree> list = this.tblOrganizaService.getJTTreeNodeId(nodeId);
                str = JSONObject.toJSONString(list);
            }
        } else {
            try {
                str = HttpClient.request(HttpClient.getOrgUrl, fields, null);
                if (!StringUtils.isNotBlank(str)) {
                    List<Tree> list = this.tblOrganizaService.getJTNodeAllGS(nodeId);
                    str = JSONObject.toJSONString(list);
                }
                return str;
            } catch (Exception e) {
                List<Tree> list = this.tblOrganizaService.getJTNodeAllGS(nodeId);
                str = JSONObject.toJSONString(list);
            }
        }
        return str;
    }


    @RequestMapping(value = "/org/saveorg", method = {RequestMethod.POST})
    @ApiOperation(value = "公司管理-新建")
    public String saveorg(HttpServletRequest request, TblOrganization org,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                          @ApiParam(name = "selectedUser", value = "登录用户主键", required = false) String selectedUser) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String pid = String.valueOf(staff.getCurrentOrg().getOrgid());
            try {
                if (org.getOrgtype() == null) {
                    org.setOrgtype(1);
                }
                if (org.getOrderid() == null) {
                    org.setOrderid(888);
                }
                BigDecimal orgid;

                if (org.getOrgid() != null) {
                    TblOrganization organization = tblOrganizaService.findById(org.getOrgid().toString());
                    orgid = organization.getOrgid();
                    organization.setOrgmeno(org.getOrgmeno());
                    organization.setOrgname(org.getOrgname());
                    organization.setOrgnumber(org.getOrgnumber());
                    organization.setMemo(org.getMemo());
                    organization.setIszy(org.getIszy());
                    organization.setIsautonumber(org.getIsautonumber());
                    organization.setIsautonumber(org.getIsautonumber());
                    organization.setWrittenByDept(org.getWrittenByDept());
                    tblOrganizaService.modiOrganization(organization);
                    return JsonBean.success("修改成功");
                } else {
                    if (org.getFatherorgid() == null) {
                        org.setFatherorgid(new BigDecimal(pid));
                    }
                    this.tblOrganizaService.addReturnId(org);
                    orgid = org.getOrgid();

                }
                if (org.getIsautonumber() == 1) {
                    tblAutonoNumberService.saveOrgNumber(orgid);
                }
                if (org.getOrgtype() != null && org.getOrgtype() != 0) {
                    tblOrganizaService.isCompanyAddWPZJ(org);
                }

                resultMap.put("code", "1");
                resultMap.put("msg", "成功");
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();

            } catch (Exception e) {
                e.printStackTrace();

            }
            return result;
        } else {
            TblOrganizationMySql orgMySql = new TblOrganizationMySql();
            BeanUtils.copyProperties(org, orgMySql);
            String pid = String.valueOf(staff.getCurrentOrg().getOrgid());
            try {
                if (orgMySql.getOrgtype() == null) {
                    orgMySql.setOrgtype(1);
                }
                if (orgMySql.getOrderid() == null) {
                    orgMySql.setOrderid(888);
                }
                BigDecimal orgid;

                if (orgMySql.getOrgid() != null) {
                    TblOrganizationMySql organization = tblOrganizaService.findByMySqlId(orgMySql.getOrgid().toString());
                    orgid = organization.getOrgid();
                    organization.setOrgmeno(orgMySql.getOrgmeno());
                    organization.setOrgname(orgMySql.getOrgname());
                    organization.setOrgnumber(orgMySql.getOrgnumber());
                    organization.setMemo(orgMySql.getMemo());
                    organization.setIszy(orgMySql.getIszy());
                    organization.setIsautonumber(orgMySql.getIsautonumber());
                    organization.setIsautonumber(orgMySql.getIsautonumber());
                    organization.setWrittenByDept(orgMySql.getWrittenByDept());
                    tblOrganizaService.modiOrganizationMySql(organization);
                    return JsonBean.success("修改成功");
                } else {
                    if (orgMySql.getFatherorgid() == null) {
                        orgMySql.setFatherorgid(new BigDecimal(pid));
                    }
                    this.tblOrganizaService.addMySqlReturnId(orgMySql);
                    orgid = orgMySql.getOrgid();

                }
                if (orgMySql.getIsautonumber() == 1) {
                    tblAutonoNumberService.saveOrgNumber(orgid);
                }
                if (orgMySql.getOrgtype() != null && orgMySql.getOrgtype() != 0) {
                    tblOrganizaService.isCompanyAddMySqlWPZJ(orgMySql);
                }

                resultMap.put("code", "1");
                resultMap.put("msg", "成功");
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();

            } catch (Exception e) {
                e.printStackTrace();

            }
            return result;
        }
    }

    @PostMapping(value = "/importOrganClassExcel")
    @ApiOperation(value = "组织架构-导入")
    @ResponseBody
    public String importRiskClassExcel(HttpServletRequest request, MultipartFile file,
                                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        InputStream in = file.getInputStream();
        XSSFWorkbook workbook = new XSSFWorkbook(in);
        String pid = request.getParameter("pid");
        try {
            //TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            XSSFCell cell = null;
            XSSFRow row = null;
            String twoContent = null;
            List<TblOrganization> list = new ArrayList<>();
            for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
                //获取工作薄中的工作表
                XSSFSheet sheet = workbook.getSheetAt(i);
                //遍历工作表的行,从第3行开始读数据(索引从0开始)
                for (int x = 1; x < sheet.getPhysicalNumberOfRows(); x++) {
                    TblOrganization org = new TblOrganization();
                    if (pid == null || pid.equals("")) {
                        pid = staff.getCurrentOrg().getOrgid().toString();
                    }
                    org.setFatherorgid(new BigDecimal(pid));
                    row = sheet.getRow(x);
                    //如果此工作表有数据
                    if (row != null) {
                        org.setOrgtype(0);
                        //遍历每行中每列的数据 row.getPhysicalNumberOfCells()
                        //获取单元格
                        cell = row.getCell(0);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            org.setOrgnumber(cell.getStringCellValue());

                        }
                        cell = row.getCell(1);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            org.setOrgname(cell.getStringCellValue());
                        }
                        cell = row.getCell(2);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            twoContent = cell.getStringCellValue();
                            Integer audit = 0;
                            if (twoContent != "" && twoContent.equals("是")) {
                                audit = 1;
                            }
                            org.setAuditType(audit);

                        }
                        cell = row.getCell(3);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            org.setOrgmeno(cell.getStringCellValue());

                        }
                        cell = row.getCell(4);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            org.setMemo(cell.getStringCellValue());

                        }
                    }
                    tblOrganizaService.saveAtionHangYe(org);
                }
            }
        } finally {
            //读取完毕则关闭流
            in.close();
            workbook.close();
        }
        return JsonBean.success();
    }

    @RequestMapping(value = "/org/save", method = {RequestMethod.POST})
    @ApiOperation(value = "组织架构-新增")
    public String orgSave(HttpServletRequest request, TblOrganization org,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                          @ApiParam(name = "selectedUser", required = false) String selectedUser) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        BigDecimal orgid;
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        String pid = String.valueOf(staff.getCurrentOrg().getOrgid());
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            org.setFatherorgid(new BigDecimal(pid));
            if (org.getOrgtype() == null) {
                org.setOrgtype(0);
            }
            if (org.getOrderid() == null) {
                org.setOrderid(888);
            }
            if (org.getOrgid() != null) {
                TblOrganization organization = tblOrganizaService.findByOrg(org.getOrgid());
                pid = String.valueOf(organization.getOrgid());
                organization.setOrgnumber(org.getOrgnumber());
                organization.setOrgname(org.getOrgname());
                organization.setOrgmeno(org.getOrgmeno());
                organization.setMemo(org.getMemo());
                organization.setAuditType(org.getAuditType());
                organization.setWrittenByDept(org.getWrittenByDept());
                tblOrganizaService.updateZuZhi(organization);
            } else {
                tblOrganizaService.addReturnOrg(org);
            }

            orgid = org.getOrgid();
            //organizationService.add(org);
            if (org.getOrgtype() != null && org.getOrgtype() != 0) {
                TblOrganization neworg = tblOrganizaService.isCompanyAddWPZ(org);
                orgid = neworg.getOrgid();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();

            return result;
        } else {
            TblOrganizationMySql orgMySql = new TblOrganizationMySql();
            BeanUtils.copyProperties(org, orgMySql);
            orgMySql.setFatherorgid(new BigDecimal(pid));
            if (orgMySql.getOrgtype() == null) {
                orgMySql.setOrgtype(0);
            }
            if (orgMySql.getOrderid() == null) {
                orgMySql.setOrderid(888);
            }
            if (orgMySql.getOrgid() != null) {
                TblOrganizationMySql organization = tblOrganizaService.findByMySqlOrg(orgMySql.getOrgid());
                pid = String.valueOf(organization.getOrgid());
                organization.setOrgnumber(orgMySql.getOrgnumber());
                organization.setOrgname(orgMySql.getOrgname());
                organization.setOrgmeno(orgMySql.getOrgmeno());
                organization.setMemo(orgMySql.getMemo());
                organization.setAuditType(orgMySql.getAuditType());
                organization.setWrittenByDept(orgMySql.getWrittenByDept());
                tblOrganizaService.updateMySqlZuZhi(organization);
            } else {
                tblOrganizaService.addMySqlReturnOrg(orgMySql);
            }

            orgid = orgMySql.getOrgid();
            //organizationService.add(org);
            if (orgMySql.getOrgtype() != null && orgMySql.getOrgtype() != 0) {
                TblOrganizationMySql neworg = tblOrganizaService.isCompanyAddMySqlWPZ(orgMySql);
                orgid = neworg.getOrgid();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();

            return result;
        }
    }


    @RequestMapping(value = "/org/hy_save", method = {RequestMethod.POST})
    @ApiOperation(value = "机构管理-行业架构-保存")
    public String orgHYSave(HttpServletRequest request, TblOrganization org,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                            @ApiParam(name = "selectedUser", value = "前端传的ID", required = false) String selectedUser) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        BigDecimal orgid;
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        String pid = String.valueOf(staff.getCurrentOrg().getOrgid());
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (org.getOrgid() != null) {
                TblOrganization organization = tblOrganizaService.findById(org.getOrgid().toString());
                // orgid = org.getOrgid();
                organization.setFatherorgid(org.getFatherorgid());
                organization.setOrgname(org.getOrgname());
                organization.setOrgnumber(org.getOrgnumber());
                organization.setMemo(org.getMemo());
                organization.setOrgmeno(org.getOrgmeno());
                organization.setOrgtype(org.getOrgtype());
                tblOrganizaService.updateAtionHangYe(organization);
            } else {
                TblOrganization ation = new TblOrganization();
                ation.setFatherorgid(org.getFatherorgid());
                ation.setOrgname(org.getOrgname());
                ation.setOrgnumber(org.getOrgnumber());
                ation.setMemo(org.getMemo());
                ation.setOrgmeno(org.getOrgmeno());
                ation.setOrgtype(100);
                tblOrganizaService.saveAtionHangYe(ation);
            }


            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            if (org.getOrgid() != null) {
                TblOrganizationMySql organization = tblOrganizaService.findByMySqlId(org.getOrgid().toString());
                // orgid = org.getOrgid();
                organization.setFatherorgid(org.getFatherorgid());
                organization.setOrgname(org.getOrgname());
                organization.setOrgnumber(org.getOrgnumber());
                organization.setMemo(org.getMemo());
                organization.setOrgmeno(org.getOrgmeno());
                organization.setOrgtype(org.getOrgtype());
                tblOrganizaService.updateMySqlAtionHangYe(organization);
            } else {
                TblOrganization ation = new TblOrganization();
                ation.setFatherorgid(org.getFatherorgid());
                ation.setOrgname(org.getOrgname());
                ation.setOrgnumber(org.getOrgnumber());
                ation.setMemo(org.getMemo());
                ation.setOrgmeno(org.getOrgmeno());
                ation.setOrgtype(100);
                tblOrganizaService.saveAtionHangYe(ation);
            }


            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @RequestMapping(value = "/org/modife", method = {RequestMethod.POST})
    @ApiOperation(value = "公司管理-修改前查询")
    public String orgmodife(HttpServletRequest request,
                            @ApiParam(name = "pid", required = false) String pid) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        String selectedUser = request.getParameter("selectedUser");
        Integer orderid = (Integer) tblOrganizaService.countOrg();
        JSONObject jsonObj = new JSONObject(orderid);
        result = jsonObj.toString();
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (pid == null || selectedUser == null) {
                resultMap = (Map<String, Object>) new HashMap<String, Object>(0);
            } else {
                resultMap.put("code", 1);
                TblOrganization organ = tblOrganizaService.findById(selectedUser);
                JSONObject jsonObject = new JSONObject((Map<String, Object>) organ);
                result = jsonObject.toString();

            }
            return result;
        } else {
            if (pid == null || selectedUser == null) {
                resultMap = (Map<String, Object>) new HashMap<String, Object>(0);
            } else {
                resultMap.put("code", 1);
                TblOrganizationMySql organ = tblOrganizaService.findByMySqlId(selectedUser);
                JSONObject jsonObject = new JSONObject((Map<String, Object>) organ);
                result = jsonObject.toString();

            }
            return result;
        }
    }


    @RequestMapping(value = "/org/gsdel", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "公司管理-启用/弃用")
    public @ResponseBody
    String gs(HttpServletRequest request,
              @ApiParam(name = "orgid", required = false) String orgid,
              @ApiParam(name = "str", required = false) String str) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (orgid != null && !orgid.equals("")) {
                TblOrganization organization = tblOrganizaService.findByOrgid(orgid);
                if (str != null && str.equals("1")) {
                    organization.setStatus(DEL_NO);
                    Set<TblOrganization> childrens = organization.getChildren();
                    if (childrens != null && childrens.size() > 0) {
                        medifeOrg(childrens);
                    }
                } else {
                    organization.setStatus(DEL_YES);
                    Set<TblOrganization> childrens = organization.getChildren();
                    if (childrens != null && childrens.size() > 0) {
                        medifeOrgq(childrens);
                    }
                }
                tblOrganizaService.modify(organization);
                //更新公司
                TblOrganization belongToCompany = treeService.belongToCompany((organization.getFatherorgid().toString()));
                redisOrgController.insertOrgOne(belongToCompany.getOrgid());
                redisOrgController.insertOrgOne(organization.getOrgid());
                return JsonBean.success();
            }
            return JsonBean.error("操作失败");
        } else {
            if (orgid != null && !orgid.equals("")) {
                TblOrganizationMySql organization = tblOrganizaService.findByMySqlOrgid(orgid);
                if (str != null && str.equals("1")) {
                    organization.setStatus(DEL_NO);
                    Set<TblOrganizationMySql> childrens = organization.getChildren();
                    if (childrens != null && childrens.size() > 0) {
                        medifeMySqlOrg(childrens);
                    }
                } else {
                    organization.setStatus(DEL_YES);
                    Set<TblOrganizationMySql> childrens = organization.getChildren();
                    if (childrens != null && childrens.size() > 0) {
                        medifeMySqlOrgq(childrens);
                    }
                }
                tblOrganizaService.modifyMySql(organization);
                //更新公司
                TblOrganizationMySql belongToCompany = treeService.belongToMySqlCompany((organization.getFatherorgid().toString()));
                redisOrgController.insertOrgOne(belongToCompany.getOrgid());
                redisOrgController.insertOrgOne(organization.getOrgid());
                return JsonBean.success();
            }
            return JsonBean.error("操作失败");
        }
    }

    public void medifeOrg(Set<TblOrganization> childrens) {
        if (childrens != null && childrens.size() > 0) {
            for (TblOrganization tblOrganization : childrens) {
                tblOrganization.setStatus(DEL_NO);
                this.tblOrganizaService.modify(tblOrganization);
                medifeOrg(tblOrganization.getChildren());
            }
        }
    }

    public void medifeMySqlOrg(Set<TblOrganizationMySql> childrens) {
        if (childrens != null && childrens.size() > 0) {
            for (TblOrganizationMySql tblOrganization : childrens) {
                tblOrganization.setStatus(DEL_NO);
                this.tblOrganizaService.modifyMySql(tblOrganization);
                medifeMySqlOrg(tblOrganization.getChildren());
            }
        }
    }

    public void medifeOrgq(Set<TblOrganization> childrens) throws Exception {

        if (childrens != null && childrens.size() > 0) {
            for (TblOrganization tblOrganization : childrens) {
                tblOrganization.setStatus(DEL_YES);
                this.tblOrganizaService.modify(tblOrganization);
                medifeOrgq(tblOrganization.getChildren());
            }
        }
    }

    public void medifeMySqlOrgq(Set<TblOrganizationMySql> childrens) throws Exception {

        if (childrens != null && childrens.size() > 0) {
            for (TblOrganizationMySql tblOrganization : childrens) {
                tblOrganization.setStatus(DEL_YES);
                this.tblOrganizaService.modifyMySql(tblOrganization);
                medifeMySqlOrgq(tblOrganization.getChildren());
            }
        }
    }


    @RequestMapping(value = "/org/isQY", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "公司管理/组织架构-删除")
    public @ResponseBody
    String saveall(HttpServletRequest request,
                   @ApiParam(name = "str", required = false) String str) throws Exception {
//        String str = request.getParameter("orgid");
        String[] orgids = str.split(",");
        boolean reuslt = false;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (str != null && str != "") {
                for (String orgid : orgids) {
                    if (orgid != null && !orgid.equals("")) {
                        TblOrganization organ = tblOrganizaService.findByOrgid(orgid);
                        if (organ.getStatus() == null) {
                            List<TblOrganization> list = tblOrganizaService.gsisXj(orgid);
                            if (list == null || list.size() <= 1) {
                                List<TblOrganization> findChildrenByOrgid = tblOrganizaService.findChildrenByOrgid(orgid);
                                if (findChildrenByOrgid != null && findChildrenByOrgid.size() > 0) {
                                    if (!tblStaffService.validateOrgExistStaff(findChildrenByOrgid)) {
                                        tblOrganizaService.deleteOrg(organ);
                                        tblAutonoNumberService.deleteOrgNo(organ.getOrgid());
                                        reuslt = true;
                                    } else {
                                        return JsonBean.error("该架构下挂有用户");
                                    }
                                } else {
                                    tblOrganizaService.deleteOrg(organ);
                                    tblAutonoNumberService.deleteOrgNo(organ.getOrgid());
                                    reuslt = true;
                                }
                            } else {
                                return JsonBean.error("有子级标签");
                            }
                        } else {
                            if (organ.getStatus() != null && organ.getStatus() == 0) {
                                return JsonBean.error("已启用不可对其修改");
                            }
                            if (organ.getStatus() != null && organ.getStatus() == 1) {
                                return JsonBean.error("已废弃");
                            }
                        }
                    }
                }
            }
            if (reuslt) {
                return JsonBean.success();
            }
            return JsonBean.error("请选择");
        } else {
            if (str != null && str != "") {
                for (String orgid : orgids) {
                    if (orgid != null && !orgid.equals("")) {
                        TblOrganizationMySql organ = tblOrganizaService.findByMySqlOrgid(orgid);
                        if (organ.getStatus() == null) {
                            List<TblOrganizationMySql> list = tblOrganizaService.gsisXjMySql(orgid);
                            if (list == null || list.size() <= 1) {
                                List<TblOrganizationMySql> findChildrenByOrgid = tblOrganizaService.findChildrenByMySqlOrgid(orgid);
                                if (findChildrenByOrgid != null && findChildrenByOrgid.size() > 0) {
                                    if (!tblStaffService.validateOrgExistMySqlStaff(findChildrenByOrgid)) {
                                        tblOrganizaService.deleteMySqlOrg(organ);
                                        tblAutonoNumberService.deleteOrgNo(organ.getOrgid());
                                        reuslt = true;
                                    } else {
                                        return JsonBean.error("该架构下挂有用户");
                                    }
                                } else {
                                    tblOrganizaService.deleteMySqlOrg(organ);
                                    tblAutonoNumberService.deleteOrgNo(organ.getOrgid());
                                    reuslt = true;
                                }
                            } else {
                                return JsonBean.error("有子级标签");
                            }
                        } else {
                            if (organ.getStatus() != null && organ.getStatus() == 0) {
                                return JsonBean.error("已启用不可对其修改");
                            }
                            if (organ.getStatus() != null && organ.getStatus() == 1) {
                                return JsonBean.error("已废弃");
                            }
                        }
                    }
                }
            }
            if (reuslt) {
                return JsonBean.success();
            }
            return JsonBean.error("请选择");
        }
    }


    @RequestMapping(value = "/qxsd/leftorg", method = {RequestMethod.POST})
    @ApiOperation(value = "菜单设定-左侧列表")
    public Map<String, Object> qxLeftorg(HttpServletRequest request,
                                         @RequestParam(name = "pid", required = false) BigDecimal pid,
                                         @RequestParam(name = "oneLevel", required = true) Boolean oneLevel,
                                         @ApiParam(name = "token", value = "登录用户token", required = true) String token) throws Exception {
        //TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        List tree = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal orgid = pid == null ? staff.getCurrentOrg().getOrgid() : pid;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblOrganization tblOrganization = tblOrganizaService.findById(orgid.toString());

            Jedis jedis = JedisUtil.getJedis();
            try {
                if (jedis.exists(RedisFinalUtis.ORGUSERSTR + orgid)) {
                    tree = Collections.singletonList(jedis.get(RedisFinalUtis.ORGUSERSTR + orgid));
                } else {
                    if (!oneLevel) {
                        tree = tblOrganizaService.getOrgTreeLefts(orgid);
                    } else {
                        tree = tblOrganizaService.getOrgTreeLeftsOneLevel(orgid);
                    }

                }
                resultMap.put("children", tree);
                resultMap.put("orgid", orgid);
                resultMap.put("orgname", tblOrganization.getOrgname());
                resultMap.put("fatherorgid", tblOrganization.getFatherorgid());
                resultMap.put("targetFrame", "listFrame");

                return resultMap;
            } finally {
                JedisUtil.returnResource(jedis);
            }
        } else {
            TblOrganizationMySql tblOrganization = tblOrganizaService.findByMySqlId(orgid.toString());

            Jedis jedis = JedisUtil.getJedis();
            try {
                if (jedis.exists(RedisFinalUtis.ORGUSERSTR + orgid)) {
                    tree = Collections.singletonList(jedis.get(RedisFinalUtis.ORGUSERSTR + orgid));
                } else {
                    if (!oneLevel) {
                        tree = tblOrganizaService.getOrgTreeLefts(orgid);
                    } else {
                        tree = tblOrganizaService.getOrgTreeLeftsOneLevel(orgid);
                    }

                }
                resultMap.put("children", tree);
                resultMap.put("orgid", orgid);
                resultMap.put("orgname", tblOrganization.getOrgname());
                resultMap.put("fatherorgid", tblOrganization.getFatherorgid());
                resultMap.put("targetFrame", "listFrame");

                return resultMap;
            } finally {
                JedisUtil.returnResource(jedis);
            }
        }
    }


    @RequestMapping(value = "/org/list", method = {RequestMethod.POST})
    @ApiOperation(value = "组织架构列表")
    public String orgList(HttpServletRequest request, Find find,
                          @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                          @ApiParam(name = "token", value = "登录用户token", required = false) String token,
                          @ApiParam(name = "pid", required = false) BigDecimal pid,
                          @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch
    ) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(String.valueOf(token));
                if (pid == null) {
                    pid = staff.getCurrentOrg().getOrgid();
                }
                Map<String, Object> resultMap = tblOrganizaService.findAllOrgBM(pageNumber, pageSize, find, pid);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(String.valueOf(token));
                if (pid == null) {
                    pid = staff.getCurrentOrg().getOrgid();
                }
                Map<String, Object> resultMap = tblOrganizaService.findAllMySqlOrgBM(pageNumber, pageSize, find, pid);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @RequestMapping(value = "/org/hy_left", method = {RequestMethod.POST})
    @ApiOperation(value = "行业架构-左侧菜单")
    public String orgHy_Left(HttpServletRequest request) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            List<TblOrganization> tree = tblOrganizaService.getHyOrgTree();
            TblOrganization org = tblOrganizaService.getHY();
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            resultMap.put("tree", tree);
            resultMap.put("orgid", org.getOrgid());
            resultMap.put("treeName", org.getOrgname());
            resultMap.put("targetFrame", "mainFramex");
            JSONObject json = new JSONObject(resultMap);
            result = json.toString();
            return result;
        } else {
            List<TblOrganizationMySql> tree = tblOrganizaService.getMySqlHyOrgTree();
            TblOrganizationMySql org = tblOrganizaService.getMySqlHY();
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            resultMap.put("tree", tree);
            resultMap.put("orgid", org.getOrgid());
            resultMap.put("treeName", org.getOrgname());
            resultMap.put("targetFrame", "mainFramex");
            JSONObject json = new JSONObject(resultMap);
            result = json.toString();
            return result;
        }
    }


    @ApiOperation(value = "行业架构--》列表页")
    @RequestMapping(value = "/org/hy_list", method = {RequestMethod.POST})
    public String orgHyList(HttpServletRequest request,
                            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                            @ApiParam(name = "staffId", required = false) String staffId,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                            String pid) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblOrganization organization = tblOrganizaService.findByname("行业");
            if (pid == null || pid == "") {
                pid = organization.getOrgid().toString();
            }
            if (staffId == null || staffId.equals("")) {
                staffId = organization.getOrgid().toString();
            }
            if (staffId == null || staffId.equals("")) {
                resultMap = tblOrganizaService.findAllHYOrg(pageNumber, pageSize);
            } else {
                resultMap = tblOrganizaService.findAllHYOrgStaffid(pageNumber, pageSize, staffId, token, pid);
                //resultMap = tblOrganizaService.findAllHYOrgs(pageNumber,pageSize,pid);

            }
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblOrganizationMySql organization = tblOrganizaService.findByMySqlname("行业");
            if (pid == null || pid == "") {
                pid = organization.getOrgid().toString();
            }
            if (staffId == null || staffId.equals("")) {
                staffId = organization.getOrgid().toString();
            }
            if (staffId == null || staffId.equals("")) {
                resultMap = tblOrganizaService.findAllHYOrg(pageNumber, pageSize);
            } else {
                resultMap = tblOrganizaService.findAllHYOrgStaffid(pageNumber, pageSize, staffId, token, pid);
                //resultMap = tblOrganizaService.findAllHYOrgs(pageNumber,pageSize,pid);

            }
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    private String result(HttpServletRequest request) {
        return null;
    }


    @RequestMapping(value = "/org/checkHyName", method = {RequestMethod.POST})
    @ApiOperation(value = "验证行业名称重复")
    public @ResponseBody
    String checkHyName(HttpServletRequest request, TblOrganization org) {
        String pid = request.getParameter("pid");
        org.setOrgnumber(request.getParameter("code"));
        String id = request.getParameter("id");
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (org.getOrgid() == null && id != null) {
                org.setOrgid(new BigDecimal(id));
            }
            org.setOrgname(request.getParameter("name"));
            List<TblOrganizationMySql> findOrgTree = tblOrganizaService.findMySqlPid(pid);
            //修改时验证
            if (org.getOrgid() != null) {
                //旧数据
                TblOrganizationMySql beforeorg = tblOrganizaService.findByMySqlIdOrgid(org.getOrgid().toString());
                //编号,名称相同,可以提交
                if (org.getOrgnumber().equals(beforeorg.getOrgnumber()) && org.getOrgname().equals(beforeorg.getOrgname())) {
                    return JsonBean.success();
                }
                //编号相同,名称不同
                if (org.getOrgnumber().equals(beforeorg.getOrgnumber()) && !org.getOrgname().equals(beforeorg.getOrgname())) {
                    for (TblOrganizationMySql tblOrganization : findOrgTree) {
                        if (org.getOrgname().equals(tblOrganization.getOrgname())) {
                            return JsonBean.error("行业名称重复1");
                        }
                        if (org.getOrgnumber().equals(beforeorg.getOrgnumber())) {
                            return JsonBean.success();
                        }
                    }
                }
                //名称相同,编号不同
                if (!org.getOrgnumber().equals(beforeorg.getOrgnumber()) && org.getOrgname().equals(beforeorg.getOrgname())) {
                    for (TblOrganizationMySql tblOrganization : findOrgTree) {
                        if (org.getOrgnumber().equals(tblOrganization.getOrgnumber())) {
                            return JsonBean.error("行业编号重复2");
                        }
                        if (org.getOrgname().equals(beforeorg.getOrgname())) {
                            return JsonBean.success();
                        }
                    }
                }
            }
            //新建时验证
            for (TblOrganizationMySql tblOrganization : findOrgTree) {
                if (org.getOrgnumber().equals(tblOrganization.getOrgnumber())) {
                    return JsonBean.error("行业编号重复3");
                }
                if (org.getOrgname().equals(tblOrganization.getOrgname())) {
                    return JsonBean.error("行业名称重复4");
                }
            }
            return JsonBean.success();
        } else {
            if (org.getOrgid() == null && id != null) {
                org.setOrgid(new BigDecimal(id));
            }
            org.setOrgname(request.getParameter("name"));
            List<TblOrganizationMySql> findOrgTree = tblOrganizaService.findMySqlPid(pid);
            //修改时验证
            if (org.getOrgid() != null) {
                //旧数据
                TblOrganizationMySql beforeorg = tblOrganizaService.findByMySqlIdOrgid(org.getOrgid().toString());
                //编号,名称相同,可以提交
                if (org.getOrgnumber().equals(beforeorg.getOrgnumber()) && org.getOrgname().equals(beforeorg.getOrgname())) {
                    return JsonBean.success();
                }
                //编号相同,名称不同
                if (org.getOrgnumber().equals(beforeorg.getOrgnumber()) && !org.getOrgname().equals(beforeorg.getOrgname())) {
                    for (TblOrganizationMySql tblOrganization : findOrgTree) {
                        if (org.getOrgname().equals(tblOrganization.getOrgname())) {
                            return JsonBean.error("行业名称重复1");
                        }
                        if (org.getOrgnumber().equals(beforeorg.getOrgnumber())) {
                            return JsonBean.success();
                        }
                    }
                }
                //名称相同,编号不同
                if (!org.getOrgnumber().equals(beforeorg.getOrgnumber()) && org.getOrgname().equals(beforeorg.getOrgname())) {
                    for (TblOrganizationMySql tblOrganization : findOrgTree) {
                        if (org.getOrgnumber().equals(tblOrganization.getOrgnumber())) {
                            return JsonBean.error("行业编号重复2");
                        }
                        if (org.getOrgname().equals(beforeorg.getOrgname())) {
                            return JsonBean.success();
                        }
                    }
                }
            }
            //新建时验证
            for (TblOrganizationMySql tblOrganization : findOrgTree) {
                if (org.getOrgnumber().equals(tblOrganization.getOrgnumber())) {
                    return JsonBean.error("行业编号重复3");
                }
                if (org.getOrgname().equals(tblOrganization.getOrgname())) {
                    return JsonBean.error("行业名称重复4");
                }
            }
            return JsonBean.success();
        }
    }

    @RequestMapping(value = "/org/hy_msave", method = {RequestMethod.POST})
    @ApiOperation(value = "行业架构-新增")
    public String orgHYModifySave(HttpServletRequest request,
                                  @RequestParam(value = "id", required = false) String id,
                                  @RequestParam(value = "pid", required = false) String pid,
                                  @RequestParam(value = "code", required = false) String code,
                                  @RequestParam(value = "name", required = false) String name,
                                  @RequestParam(value = "desc", required = false) String desc,
                                  @RequestParam(value = "memo", required = false) String memo) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (id != null && !id.equals("")) {

                TblOrganization org = new TblOrganization();
                org.setOrgid(new BigDecimal(id));
                org.setFatherorgid(new BigDecimal(pid));
                org.setOrgname(name);
                org.setOrgnumber(code);
                org.setMemo(memo);
                org.setOrgmeno(desc);
                org.setOrgtype(100);
                this.tblOrganizaService.saveModify(org);
            }
            if (pid == null || pid.equals("")) {
                return "访问数据成功";
            } else {
                return "访问数据错误" + pid;
            }
        } else {
            if (id != null && !id.equals("")) {

                TblOrganizationMySql org = new TblOrganizationMySql();
                org.setOrgid(new BigDecimal(id));
                org.setFatherorgid(new BigDecimal(pid));
                org.setOrgname(name);
                org.setOrgnumber(code);
                org.setMemo(memo);
                org.setOrgmeno(desc);
                org.setOrgtype(100);
                this.tblOrganizaService.saveMySqlModify(org);
            }
            if (pid == null || pid.equals("")) {
                return "访问数据成功";
            } else {
                return "访问数据错误" + pid;
            }
        }
    }


    @RequestMapping(value = "/org/hy_del", method = {RequestMethod.POST})
    @ApiOperation(value = "行业架构-删除")
    public @ResponseBody
    String orgHYDel(HttpServletRequest request, String[] ids,
                    @ApiParam(name = "orgid", required = false) BigDecimal orgid,
                    @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            List<TblOrganization> tion = tblOrganizaService.isParent(orgid.toString());
            if (tion.size() > 0) {
                return JsonBean.error("请先删除包含的其他行业");
            }
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            List<TblOrganization> orgList = tblOrganizaService.findHYAuthorize(orgid.toString(), staff.getCurrentOrg().getOrgid().toString());
            if (orgList.size() > 0) {
                return JsonBean.error("有授权数据,不允许删除");
            }
            tblIndustryInnerService.deleteByOrgid(orgid);
            tblOrganizaService.delete(orgid);
            resultMap.put("code", "1");
            resultMap.put("msg", "删除成功");
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;

        } else {
            List<TblOrganizationMySql> tion = tblOrganizaService.isParentMySql(orgid.toString());
            if (tion.size() > 0) {
                return JsonBean.error("请先删除包含的其他行业");
            }
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            List<TblOrganizationMySql> orgList = tblOrganizaService.findMySqlHYAuthorize(orgid.toString(), staff.getCurrentOrg().getOrgid().toString());
            if (orgList.size() > 0) {
                return JsonBean.error("有授权数据,不允许删除");
            }
            tblIndustryInnerService.deleteByOrgid(orgid);
            tblOrganizaService.delete(orgid);
            resultMap.put("code", "1");
            resultMap.put("msg", "删除成功");
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    @RequestMapping(value = "/organAccreditByHY", method = {RequestMethod.POST})
    @ApiOperation(value = "行业架构-授权分配")
    public String organAccreditByHY(HttpServletRequest request, String[] orgids,
                                    @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();

            //TblStaff tblStaff = new TblStaff();
            String orgid = pid == null ? null
                    : pid.toString();
            List<TblOrganization> findOrgTree = treeService.findAllCompany(orgid, staff.getCurrentOrg().getAudittype());
            //List<Tree> findOrgTree = treeService.findAllCompanyALL(orgid, staff.getCurrentOrg().getAudittype());
            String ids = "";
            for (int i = 0; i < orgids.length; i++) {
                ids += orgids[i] + ",";
            }
            resultMap.put("ids", ids);
            resultMap.put("findOrgTree", findOrgTree);
            JSONObject jsonObjectm = new JSONObject(resultMap);
            result = jsonObjectm.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();

            //TblStaff tblStaff = new TblStaff();
            String orgid = pid == null ? null
                    : pid.toString();
            List<TblOrganizationMySql> findOrgTree = treeService.findAllMySqlCompany(orgid, staff.getCurrentOrg().getAudittype());
            //List<Tree> findOrgTree = treeService.findAllCompanyALL(orgid, staff.getCurrentOrg().getAudittype());
            String ids = "";
            for (int i = 0; i < orgids.length; i++) {
                ids += orgids[i] + ",";
            }
            resultMap.put("ids", ids);
            resultMap.put("findOrgTree", findOrgTree);
            JSONObject jsonObjectm = new JSONObject(resultMap);
            result = jsonObjectm.toString();
            return result;
        }
    }

    @RequestMapping(value = "/add_hy_accredit", method = {RequestMethod.POST})
    @ApiOperation(value = "行业架构-授权分配-选定接口")
    public @ResponseBody
    String add_hy_accredit(HttpServletRequest request,
                           @ApiParam(name = "orgids", required = false) String orgids,
                           @ApiParam(name = "selid", required = false) String selid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            //String selid = request.getParameter("selid");
            List<TblOrganization> parentHy = tblOrganizaService.parentHy(orgids);
            for (int i = 0; i < parentHy.size(); i++) {
                TblOrganization o = parentHy.get(i);
                TblIndustryInner ii = new TblIndustryInner();
                ii.setOrgid(Long.parseLong(o.getOrgid().toString()));
                ii.setIndustryid(Long.parseLong(selid));
                tblIndustryInnerService.delete(ii);
                tblIndustryInnerService.save(ii);
            }
            String[] ids = orgids.split(",");
            for (int i = 0; i < ids.length; i++) {
                TblIndustryInner ii = new TblIndustryInner();
                ii.setOrgid(Long.parseLong(ids[i]));
                ii.setIndustryid(Long.parseLong(selid));
                try {
                    tblIndustryInnerService.delete(ii);
                    tblIndustryInnerService.save(ii);

                } catch (Exception e) {
                }
            }
            return JsonBean.success();
        } else {
            List<TblOrganizationMySql> parentHy = tblOrganizaService.parentMySqlHy(orgids);
            for (int i = 0; i < parentHy.size(); i++) {
                TblOrganizationMySql o = parentHy.get(i);
                TblIndustryInnerMySql ii = new TblIndustryInnerMySql();
                ii.setOrgid(Long.parseLong(o.getOrgid().toString()));
                ii.setIndustryid(Long.parseLong(selid));
                tblIndustryInnerService.deleteMySql(ii);
                tblIndustryInnerService.saveMySql(ii);
            }
            String[] ids = orgids.split(",");
            for (int i = 0; i < ids.length; i++) {
                TblIndustryInnerMySql ii = new TblIndustryInnerMySql();
                ii.setOrgid(Long.parseLong(ids[i]));
                ii.setIndustryid(Long.parseLong(selid));
                try {
                    tblIndustryInnerService.deleteMySql(ii);
                    tblIndustryInnerService.saveMySql(ii);

                } catch (Exception e) {
                }
            }
            return JsonBean.success();
        }
    }


    @RequestMapping(value = "/authorize_to_del", method = {RequestMethod.POST})
    @ApiOperation(value = "行业架构-取消授权列表")
    public String authorize_to_del(HttpServletRequest request, String hyid,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String result = null;
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            //TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            List<TblOrganization> orgList = tblOrganizaService.findHYAuthorize(hyid, pid.toString());
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            resultMap.put("data", orgList);
            JSONObject jsonObjectv = new JSONObject(resultMap);
            result = jsonObjectv.toString();
            return result;
        } else {
            String result = null;
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            //TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            List<TblOrganizationMySql> orgList = tblOrganizaService.findMySqlHYAuthorize(hyid, pid.toString());
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            resultMap.put("data", orgList);
            JSONObject jsonObjectv = new JSONObject(resultMap);
            result = jsonObjectv.toString();
            return result;
        }
    }

    @PostMapping(value = "/authorize_del")
    @ApiOperation(value = "行业架构-取消授权确定")
    public @ResponseBody
    String authorize_del(HttpServletRequest request, String hyid, String[] orgids) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            for (int i = 0; i < orgids.length; i++) {
                TblIndustryInner ii = new TblIndustryInner();
                ii.setOrgid(Long.parseLong(hyid));
                ii.setIndustryid(Long.parseLong(orgids[i]));
                try {
                    tblIndustryInnerService.delete(ii);
                } catch (Exception e) {
                }
            }
            return JsonBean.success();
        } else {
            for (int i = 0; i < orgids.length; i++) {
                TblIndustryInnerMySql ii = new TblIndustryInnerMySql();
                ii.setOrgid(Long.parseLong(hyid));
                ii.setIndustryid(Long.parseLong(orgids[i]));
                try {
                    tblIndustryInnerService.deleteMySql(ii);
                } catch (Exception e) {
                }
            }
            return JsonBean.success();
        }
    }


    @RequestMapping(value = "/user/lefts", method = {RequestMethod.POST})
    public String lefts(HttpServletRequest request,
                        @RequestParam(value = "acctid", required = false) String acctid,
                        @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
            //Integer.parseInt("common/gsgl/user_left")
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            String num = request.getParameter("type");
            resultMap.put("type", num);
            resultMap.put("acctid", acctid);
            resultMap.put("orgid", attribute1.getOrgid());
            resultMap.put("targetFrame", "mainFramex");
            String result = null;
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        } else {
            TblOrganizationMySql attribute1 = (TblOrganizationMySql) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
            //Integer.parseInt("common/gsgl/user_left")
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            String num = request.getParameter("type");
            resultMap.put("type", num);
            resultMap.put("acctid", acctid);
            resultMap.put("orgid", attribute1.getOrgid());
            resultMap.put("targetFrame", "mainFramex");
            String result = null;
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        }
    }

    @RequestMapping(value = "/user/list/two", method = {RequestMethod.POST})
    @ApiOperation(value = "主题展示-下发")
    public String userListss(HttpServletRequest request,
                             @RequestParam(value = "pageNames", required = false) String pageNames,
                             @RequestParam(value = "pid", required = false) String pid,
                             @RequestParam(value = "type", required = false) String type,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (type != null && type.length() > 0) {
                request.getSession().setAttribute("userType", type);
            }
            if (type != null && type.equals("''")) {
                type = null;
            }
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal orgid = staff.getCurrentOrg().getOrgid();
            PageInfo<TblStaff> pageInfo = new PageInfo<TblStaff>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);

            if (pid != null && pid.length() > 0) {
                resultMap = userService.findByAll(pid, pageInfo);
            } else {
                resultMap = userService.findByAllORGID(orgid, pageInfo);
            }
            resultMap.put("pid", pid);
            resultMap.put("pageBean", pageBean);
            resultMap.put("type", type);
            resultMap.put("pageNames", pageNames);
            resultMap.put("selectM", request.getParameter("selectM"));
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            if (type != null && type.length() > 0) {
                request.getSession().setAttribute("userType", type);
            }
            if (type != null && type.equals("''")) {
                type = null;
            }
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal orgid = staff.getCurrentOrg().getOrgid();
            PageInfo<TblStaffMySql> pageInfo = new PageInfo<TblStaffMySql>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);

            if (pid != null && pid.length() > 0) {
                resultMap = userService.findByAllMySql(pid, pageInfo);
            } else {
                resultMap = userService.findByAllMySqlORGID(orgid, pageInfo);
            }
            resultMap.put("pid", pid);
            resultMap.put("pageBean", pageBean);
            resultMap.put("type", type);
            resultMap.put("pageNames", pageNames);
            resultMap.put("selectM", request.getParameter("selectM"));
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @RequestMapping(value = "/user/list", method = {RequestMethod.POST})
    @ApiOperation(value = "用户管理列表-查询")
    public String userList(HttpServletRequest request, Find find,
                           @RequestParam(value = "staffid", required = false) String staffid,
                           @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                           @ApiParam(name = "pid", required = false) BigDecimal pid,
                           @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (pid == null) {
                resultMap = userService.findAllPageBean(find, pageNumber, pageSize, token, staffid);
            } else {
                resultMap = userService.findAllPageBeanPid(staffid, find, pageNumber, pageSize, pid);
            }

            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
            return result;
        } else {
            if (pid == null) {
                resultMap = userService.findAllMySqlPageBean(find, pageNumber, pageSize, token, staffid);
            } else {
                resultMap = userService.findAllMySqlPageBeanPid(staffid, find, pageNumber, pageSize, pid);
            }

            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
            return result;
        }
    }


    @RequestMapping(value = "/user/new", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-用户管理-新增页面访问接口获取信息")
    public String userNew(HttpServletRequest request, @ApiParam(name = "pid", required = false) BigDecimal pid,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            List<TblRole> roles = tblRoleService.findAll(staff.getCurrentOrg().getOrgid());
            List<TblJob> jobs = tblJobService.findAll(staff.getCurrentOrg().getOrgid());
            resultMap.put("pid", pid);
            resultMap.put("jobs", jobs);
            resultMap.put("roles", roles);
            JSONObject jsonCompanyId = new JSONObject(resultMap);
            result = jsonCompanyId.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            List<TblRoleMySql> roles = tblRoleService.findAllMySql(staff.getCurrentOrg().getOrgid());
            List<TblJobMySql> jobs = tblJobService.findAllMySql(staff.getCurrentOrg().getOrgid());
            resultMap.put("pid", pid);
            resultMap.put("jobs", jobs);
            resultMap.put("roles", roles);
            JSONObject jsonCompanyId = new JSONObject(resultMap);
            result = jsonCompanyId.toString();
            return result;
        }
    }

    @RequestMapping(value = "/user/isuserName", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiParam(value = "用户权限管理-用户管理-新建前查询用户名")
    public @ResponseBody
    String ruleUpdateStatus(HttpServletRequest request,
                            @ApiParam(name = "username", required = false) String username) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (username != null && username != "") {
                TblStaff user = tblStaffService.findByUsername(username);
                if (user != null) {
                    return JsonBean.error("用户名已存在");
                } else {
                    return JsonBean.success();
                }
            } else {
                return JsonBean.error("请输入用户名称");
            }
        } else {
            if (username != null && username != "") {
                TblStaffMySql user = tblStaffService.findByMySqlUsername(username);
                if (user != null) {
                    return JsonBean.error("用户名已存在");
                } else {
                    return JsonBean.success();
                }
            } else {
                return JsonBean.error("请输入用户名称");
            }
        }
    }

    @RequestMapping(value = "/user/iseamil", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiParam("用户权限管理-用户管理-新建/修改时查询邮箱是否存在")
    public @ResponseBody
    String iseamil(HttpServletRequest request, @ApiParam(name = "email", required = false) String email) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (email != null && email != "") {
                List<TblStaff> list = tblStaffService.findByEmail(email);
                if (list != null && list.size() > 0) {
                    return JsonBean.error("邮箱已存在");
                } else {
                    return JsonBean.success();
                }
            } else {
                return JsonBean.error("请输入邮箱");
            }
        } else {
            if (email != null && email != "") {
                List<TblStaffMySql> list = tblStaffService.findByMySqlEmail(email);
                if (list != null && list.size() > 0) {
                    return JsonBean.error("邮箱已存在");
                } else {
                    return JsonBean.success();
                }
            } else {
                return JsonBean.error("请输入邮箱");
            }
        }
    }

    @RequestMapping(value = "/user/save", method = {RequestMethod.POST})
    @ApiParam(value = "用户权限管理-用户管理-新建")
    public Map<String, Object> userSave(HttpServletRequest request, TblStaff tblStaff) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (tblStaff.getOrgid() != null) {
                TblStaff user = new TblStaff();
                user.setOrgid(tblStaff.getOrgid());
                user.setRealname(tblStaff.getRealname());
                user.setStatus(tblStaff.getStatus());

                user.setFixedphone(tblStaff.getFixedphone());
                user.setMiblephone(tblStaff.getMiblephone());
                user.setAddress(tblStaff.getAddress());
                user.setEmail(tblStaff.getEmail());
                user.setMemo(tblStaff.getMemo());
                user.setUsername(tblStaff.getUsername());
                user.setJobid(tblStaff.getJobid());
                user.setRoleIdStrs(tblStaff.getRoleIdStrs());
//            if(password != null && !"".equals(password)) {
//            	user.setPassword(MD5Encrypt.encrypByMd5(password));
//            }
                if (tblStaff.getStaffid() != null) {
                    user.setStaffid(tblStaff.getStaffid());
                    tblStaffService.update(user);
                    resultMap.put("code", "1");
                    resultMap.put("msg", "修改成功");

                } else {
                    tblStaffService.add(user);
                    resultMap.put("code", "1");
                    resultMap.put("msg", "新增成功");
                }
            }
            return resultMap;
        } else {
            if (tblStaff.getOrgid() != null) {
                TblStaffMySql user = new TblStaffMySql();
                user.setOrgid(tblStaff.getOrgid());
                user.setRealname(tblStaff.getRealname());
                user.setStatus(tblStaff.getStatus());

                user.setFixedphone(tblStaff.getFixedphone());
                user.setMiblephone(tblStaff.getMiblephone());
                user.setAddress(tblStaff.getAddress());
                user.setEmail(tblStaff.getEmail());
                user.setMemo(tblStaff.getMemo());
                user.setUsername(tblStaff.getUsername());
                user.setJobid(tblStaff.getJobid());
                user.setRoleIdStrs(tblStaff.getRoleIdStrs());
//            if(password != null && !"".equals(password)) {
//            	user.setPassword(MD5Encrypt.encrypByMd5(password));
//            }
                if (tblStaff.getStaffid() != null) {
                    user.setStaffid(tblStaff.getStaffid());
                    tblStaffService.updateMySql(user);
                    resultMap.put("code", "1");
                    resultMap.put("msg", "修改成功");

                } else {
                    tblStaffService.addMySql(user);
                    resultMap.put("code", "1");
                    resultMap.put("msg", "新增成功");
                }
            }
            return resultMap;
        }
    }

//    @RequestMapping(value = "/user/msave", method = {RequestMethod.POST})
//    @ApiParam(value = "用户权限管理-用户管理-修改")
//    public String userModifySave(HttpServletRequest request,@ApiParam(name = "pid",required = false) String pid,
//                                 @RequestParam(value = "id",required = false) String id,
//                                 @RequestParam(value = "oid",required = false)  String oid,
//                                 @RequestParam(value = "realName",required = false)   String realName,
//                                 @RequestParam(value = "fixedPhone",required = false)  String fixedPhone,
//                                 @RequestParam(value = "mphone",required = false)  String mphone,
//                                 @RequestParam(value = "address",required = false)   String address,
//                                 @RequestParam(value = "email",required = false)  String email,
//                                 @RequestParam(value = "name",required = false)   String name,
//                                 @RequestParam(value = "memo",required = false)  String memo, @RequestParam(value = "jobid",required = false)  String jobid) {
//        if (id != null && !id.equals("")) {
//
//            TblOrganization org = tblOrganizaService.findById(oid);
//            TblStaff user = tblStaffService.findById(id);
//            if (org != null) {
//                user.setTblOrganization(org);
//            }
//            String status = request.getParameter("status");
//            if (status != null && status.equals("0")) {
//                user.setStatus(TblStaff.USER_DISABLE);
//            } else {
//                user.setStatus(TblStaff.USER_ENBLE);
//            }
//            String roleid = request.getParameter("roleid");
//            if (roleid != null && roleid.trim().length() > 0) {
//                TblRole tblRole = tblRoleService.findByid(roleid);
//                user.setTrole(tblRole);
//            } else {
//                user.setTrole((TblRoleUtil) null);
//            }
//            user.setRealname(realName);
//            user.setFixedphone(fixedPhone);
//            user.setMiblephone(mphone);
//            user.setAddress(address);
//            user.setEmail(email);
//            user.setMemo(memo);
//            user.setUsername(name);
//            if (jobid!=null&&jobid.trim().length()>0) {
//                user.setJobid(new BigDecimal(jobid));
//            }else {
//                user.setJobid(null);
//
//            }
//
//            tblStaffService.modify(user);
//            return JsonBean.success("操作成功");
//        }
//
//        return JsonBean.error("操作失败");
//    }


    @RequestMapping(value = "/user/modify", method = {RequestMethod.POST})
//    @ApiOperation(value = "用户权限管理-用户管理-修改")
    public String userModify(HttpServletRequest request, @ApiParam(name = "pid", required = false) String pid) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String id = request.getParameter("selectedUser");
            if (id != null && !id.equals("")) {
                TblStaff user = tblStaffService.findById(pid);
                Map<String, Object> resultMap = new HashMap<String, Object>(0);
                resultMap.put("user", user);
                TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
                List<TblRole> roles = tblRoleService.findAll(organization.getOrgid());
                List<TblJob> findAll = tblJobService.findAll(organization.getOrgid());
                resultMap.put("roles", roles);
                resultMap.put("jobs", findAll);
                resultMap.put("pid", pid);

                JSONObject jsonChoiceSearch = new JSONObject(resultMap);
                result = jsonChoiceSearch.toString();
            }
            return result;
        } else {
            String id = request.getParameter("selectedUser");
            if (id != null && !id.equals("")) {
                TblStaff user = tblStaffService.findById(pid);
                Map<String, Object> resultMap = new HashMap<String, Object>(0);
                resultMap.put("user", user);
                TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
                List<TblRole> roles = tblRoleService.findAll(organization.getOrgid());
                List<TblJob> findAll = tblJobService.findAll(organization.getOrgid());
                resultMap.put("roles", roles);
                resultMap.put("jobs", findAll);
                resultMap.put("pid", pid);

                JSONObject jsonChoiceSearch = new JSONObject(resultMap);
                result = jsonChoiceSearch.toString();
            }
            return result;
        }
    }


    @RequestMapping(value = "/user/pmodify", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-用户管理-重置密码")
    public String userPModify(HttpServletRequest request, String staffid) {
        String result = null;
        //String id = request.getParameter("selectedUser");
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (staffid != null && !staffid.equals("")) {
                //UserService srvc = (UserService) SpringContextHolder.getBean("UserService");
                TblStaff user = tblStaffService.findById(staffid);
                Map<String, Object> resultMap = new HashMap<String, Object>(0);
                resultMap.put("user", user);
                JSONObject jsonchoiceSerach = new JSONObject(resultMap);
                result = jsonchoiceSerach.toString();
            }
            return result;
        } else {
            if (staffid != null && !staffid.equals("")) {
                //UserService srvc = (UserService) SpringContextHolder.getBean("UserService");
                TblStaffMySql user = tblStaffService.findByMySqlId(staffid);
                Map<String, Object> resultMap = new HashMap<String, Object>(0);
                resultMap.put("user", user);
                JSONObject jsonchoiceSerach = new JSONObject(resultMap);
                result = jsonchoiceSerach.toString();
            }
            return result;
        }
    }

    @RequestMapping(value = "/user/psave", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-用户管理-重置密码")
    public String userPsave(HttpServletRequest request, String id,
                            String password, String password1) {
        String result = null;
        //String id = request.getParameter("uid");
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (id != null && !id.equals("")) {
                // UserService srvc = (UserService) SpringContextHolder.getBean("UserService");
                TblStaff user = tblStaffService.findById(id);
//            String pwd1 = request.getParameter("password");
//            String pwd2 = request.getParameter("password1");
                if (password.equals(password1)) {
                    user.setPassword(MD5Encrypt.encrypByMd5(password1));
                    tblStaffService.modify(user);
                }
            }
            return result;
        } else {
            if (id != null && !id.equals("")) {
                // UserService srvc = (UserService) SpringContextHolder.getBean("UserService");
                TblStaffMySql user = tblStaffService.findByMySqlId(id);
//            String pwd1 = request.getParameter("password");
//            String pwd2 = request.getParameter("password1");
                if (password.equals(password1)) {
                    user.setPassword(MD5Encrypt.encrypByMd5(password1));
                    tblStaffService.modifyMySql(user);
                }
            }
            return result;
        }
    }

    @RequestMapping(value = "/role/role_list", method = {RequestMethod.POST})
    @ApiOperation(value = "角色管理-列表")
    public String roleList(HttpServletRequest request, TblRole role,
                           @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token
    ) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            resultMap = tblRoleService.findTblRoleAll(role, pageNumber, pageSize, token);
            JSONObject jsonObjectmv = new JSONObject(resultMap);
            result = jsonObjectmv.toString();
            return result;
        } else {
            resultMap = tblRoleService.findMySqlTblRoleAll(role, pageNumber, pageSize, token);
            JSONObject jsonObjectmv = new JSONObject(resultMap);
            result = jsonObjectmv.toString();
            return result;
        }
    }


    @RequestMapping(value = "/role/modify_save", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-角色管理-修改")
    public String role_modify(HttpServletRequest request, TblRole role) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblRole newrole = tblRoleService.findByid(role.getRid().toString());
            newrole.setRdesc(role.getRdesc());
            newrole.setRname(role.getRname());
            newrole.setRstatus(role.getRstatus());
            newrole.setCompanyid(role.getCompanyid());
            tblRoleService.update(newrole);
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();

            return result;
        } else {
            TblRoleMySql newrole = tblRoleService.findByMySqlid(role.getRid().toString());
            newrole.setRdesc(role.getRdesc());
            newrole.setRname(role.getRname());
            newrole.setRstatus(role.getRstatus());
            newrole.setCompanyid(role.getCompanyid());
            BeanUtils.copyProperties(newrole, role);
            tblRoleService.updateMySql(role);
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();

            return result;
        }
    }

    @RequestMapping(value = "/job/modify_save", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-岗位管理-修改")
    public String job_modify(HttpServletRequest request, TblJob job) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblJob newJob = tblJobService.findByJobId(job.getJobid().toString());
            newJob.setJobname(job.getJobname());
            newJob.setCompanyId(job.getCompanyId());
            tblJobService.updateJob(newJob);
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();

            return result;
        } else {
            TblJobMySql newJob = tblJobService.findByMySqlJobId(job.getJobid().toString());
            newJob.setJobname(job.getJobname());
            newJob.setCompanyId(job.getCompanyId());
            tblJobService.updateMySqlJob(newJob);
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();

            return result;
        }
    }


    @RequestMapping(value = "/role/save", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-角色管理-保存")
    public String roleSave(HttpServletRequest request, TblRole role,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            if (role.getRid() != null) {
                tblRoleService.update(role);
            } else {
                TblRole tr = new TblRole();
                tr.setRname(role.getRname());
                tr.setRdesc(role.getRdesc());
                tr.setRstatus(role.getRstatus());
                tr.setCompanyid(pid);
                tblRoleService.save(tr);
            }

            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            if (role.getRid() != null) {
                tblRoleService.updateMySql(role);
            } else {
                TblRole tr = new TblRole();
                tr.setRname(role.getRname());
                tr.setRdesc(role.getRdesc());
                tr.setRstatus(role.getRstatus());
                tr.setCompanyid(pid);
                tblRoleService.saveMySql(tr);
            }

            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }

    @RequestMapping(value = "/role/role_modify", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-角色管理-修改")
    public String role_modify(HttpServletRequest request) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问数据成功"));
            String selectedId = request.getParameter("selectedId");
            if (selectedId != null && selectedId.trim().length() > 0) {
                TblRole role = tblRoleService.findByid(selectedId);
                resultMap.put("role", role);
            }
            //为页面查找区域显隐藏赋值
            String choiceSearch = request.getParameter("choiceSearch");
            if (choiceSearch == null || "".equals(choiceSearch)) {
                choiceSearch = "hide";
            }
            String choiceSearch2 = request.getParameter("choiceSearch2");
            if (choiceSearch2 == null || "".equals(choiceSearch2)) {
                choiceSearch2 = "hide";
            }
            resultMap.put("choiceSearch", choiceSearch);
            resultMap.put("choiceSearch2", choiceSearch2);
            JSONObject jsonChoiceSearch2 = new JSONObject(resultMap);
            result = jsonChoiceSearch2.toString();
            return result;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问数据成功"));
            String selectedId = request.getParameter("selectedId");
            if (selectedId != null && selectedId.trim().length() > 0) {
                TblRoleMySql role = tblRoleService.findByMySqlid(selectedId);
                resultMap.put("role", role);
            }
            //为页面查找区域显隐藏赋值
            String choiceSearch = request.getParameter("choiceSearch");
            if (choiceSearch == null || "".equals(choiceSearch)) {
                choiceSearch = "hide";
            }
            String choiceSearch2 = request.getParameter("choiceSearch2");
            if (choiceSearch2 == null || "".equals(choiceSearch2)) {
                choiceSearch2 = "hide";
            }
            resultMap.put("choiceSearch", choiceSearch);
            resultMap.put("choiceSearch2", choiceSearch2);
            JSONObject jsonChoiceSearch2 = new JSONObject(resultMap);
            result = jsonChoiceSearch2.toString();
            return result;
        }
    }

    @ApiOperation(value = "用户权限管理-角色管理-角色管理-判断角色是否使用")
    @RequestMapping(value = "/role/is_sy", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String rolesy(HttpServletRequest request) {
        String rid = request.getParameter("rid");
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            List list = tblRoleService.isSY(rid);
            if (list == null || list.size() <= 0) {
                return JsonBean.success();
            } else {
                return JsonBean.error("正在使用，无法操作");
            }
        } else {
            List list = tblRoleService.isMySqlSY(rid);
            if (list == null || list.size() <= 0) {
                return JsonBean.success();
            } else {
                return JsonBean.error("正在使用，无法操作");
            }
        }

    }

    @RequestMapping(value = "/role/modify_rstatus", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-角色管理-启用/禁用")
    public String modify_rstatus(HttpServletRequest request,
                                 String selectedId, String str) {
//        String result = null;
//        Map<String,Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (selectedId != null && selectedId.trim().length() > 0) {
                TblRole role = tblRoleService.findByid(selectedId);
                if (str != null && str.equals("1")) {
                    role.setRstatus(TblRole.DEL_YES);
                } else {
                    role.setRstatus(TblRole.DEL_NO);
                }
                tblRoleService.update(role);
            }
//        JSONObject jsonObjectMV = new JSONObject(resultMap);
//        result = jsonObjectMV.toString();
            return JsonBean.success("成功");
        } else {
            if (selectedId != null && selectedId.trim().length() > 0) {
                TblRoleMySql role = tblRoleService.findByMySqlid(selectedId);
                if (str != null && str.equals("1")) {
                    role.setRstatus(TblRole.DEL_YES);
                } else {
                    role.setRstatus(TblRole.DEL_NO);
                }
                TblRole tblRole = new TblRole();
                BeanUtils.copyProperties(role, tblRole);
                tblRoleService.updateMySql(tblRole);
            }
//        JSONObject jsonObjectMV = new JSONObject(resultMap);
//        result = jsonObjectMV.toString();
            return JsonBean.success("成功");
        }
    }

    @RequestMapping(value = "/job/job_list", method = {RequestMethod.POST})
    @ApiOperation(value = "岗位管理查询列表")
    public String jobList(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        resultMap = tblJobService.listJob(pageNumber, pageSize, token);
        JSONObject jsonObjectMv = new JSONObject(resultMap);
        result = jsonObjectMv.toString();
        return result;
    }

    @RequestMapping(value = "/role/role_del", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-角色管理-删除")
    public String role_del(HttpServletRequest request,
                           @ApiParam(name = "rid", required = false) String rid) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (rid != null && rid.trim().length() > 0) {
                TblRole role = tblRoleService.findByid(rid);
                List<TblStaff> list = tblRoleService.isSY(rid);
                if (list != null || list.size() > 0) {
                    return JsonBean.error("正在使用，无法操作");
                }
                tblRoleService.delete(role);
                //tblRoleService.deleteByRid(rid);
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            if (rid != null && rid.trim().length() > 0) {
                TblRoleMySql role = tblRoleService.findByMySqlid(rid);
                List<TblStaffMySql> list = tblRoleService.isMySqlSY(rid);
                if (list != null || list.size() > 0) {
                    return JsonBean.error("正在使用，无法操作");
                }
                tblRoleService.deleteMySql(role);
                //tblRoleService.deleteByRid(rid);
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @RequestMapping(value = "/job/save", method = {RequestMethod.POST})
    @ApiOperation(value = "岗位管理-保存")
    public String jobSave(HttpServletRequest request, TblJob job,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                          @ApiParam(name = "staffId", required = false) String staffId) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            if (job.getJobid() != null) {
                tblJobService.updateJob(job);
            } else {
                TblJob tj = new TblJob();
                // tj.setJobid(job.getJobid());
                tj.setJobname(job.getJobname());
                tj.setCompanyId(pid.toString());
                tblJobService.saveJob(tj);
            }

            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            if (job.getJobid() != null) {
                TblJobMySql jobMySql = new TblJobMySql();
                BeanUtils.copyProperties(job, jobMySql);
                tblJobService.updateMySqlJob(jobMySql);
            } else {
                TblJobMySql tj = new TblJobMySql();
                // tj.setJobid(job.getJobid());
                tj.setJobname(job.getJobname());
                tj.setCompanyId(pid.toString());
                tblJobService.saveMySqlJob(tj);
            }

            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }

    @RequestMapping(value = "/job/job_modify", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-岗位修改-根据ID查找岗位信息")
    public String job_modify(HttpServletRequest request) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问数据成功"));
            String selectedId = request.getParameter("selectedId");
            if (selectedId != null && selectedId.trim().length() > 0) {
                TblJob findByid = tblJobService.findByid(selectedId);
                resultMap.put("job", findByid);
            }
            JSONObject jsonModify = new JSONObject(resultMap);
            result = jsonModify.toString();
            return result;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问数据成功"));
            String selectedId = request.getParameter("selectedId");
            if (selectedId != null && selectedId.trim().length() > 0) {
                TblJobMySql findByid = tblJobService.findByMySqlid(selectedId);
                resultMap.put("job", findByid);
            }
            JSONObject jsonModify = new JSONObject(resultMap);
            result = jsonModify.toString();
            return result;
        }
    }


    @RequestMapping(value = "/job/job_del", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-岗位管理-删除")
    public String job_del(HttpServletRequest request,
                          TblJob job,
                          @ApiParam(name = "selectedId", required = false) String selectedId) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            List<TblStaff> staff = tblStaffService.findByJobid(job.getJobid());
            if (staff.size() > 0) {
                return JsonBean.error("已授权，不能删除");
            }
            tblJobService.deleteJob(job.getJobid());
            resultMap.put("code", "1");
            resultMap.put("msg", "删除成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            List<TblStaffMySql> staff = tblStaffService.findByMySqlJobid(job.getJobid());
            if (staff.size() > 0) {
                return JsonBean.error("已授权，不能删除");
            }
            tblJobService.deleteJob(job.getJobid());
            resultMap.put("code", "1");
            resultMap.put("msg", "删除成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }

    @RequestMapping(value = "/qxsd/qx", method = {RequestMethod.POST})
    public String qx(HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        JSONObject jsonObjectMAV = new JSONObject(resultMap);
        result = jsonObjectMAV.toString();
        return result;
    }

    @RequestMapping(value = "/user/info", method = {RequestMethod.POST})
    @ApiOperation(value = "用户信息")
    public Object userInfo(HttpServletRequest request,
                           Find find,
                           @RequestParam(name = "staffid", value = "staffid", required = false) String staffid,
                           @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                           @ApiParam(name = "pid", required = false) BigDecimal pid,
                           @ApiParam(name = "staffId", value = "staffId", required = false) String staffId) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (staffId != null && !staffId.equals("")) {
                TblStaff user;
                if (staffid != null) {
                    user = userService.findById(staffid);
                } else {
                    user = userService.findById(staffId);
                }

                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                BigDecimal orgid = staff.getCurrentOrg().getOrgid();
                List<TblRole> roles = tblRoleService.findAll(orgid);
                List<TblJob> findAll = tblJobService.findAll(orgid);
                resultMap.put("roles", roles);
                resultMap.put("jobs", findAll);
                resultMap.put("user", user);
                JSONObject jsonObjectMV = new JSONObject(resultMap);
                result = jsonObjectMV.toString();

            } else {
                return this.userList(request, find, staffid, pageNumber, pageSize, token, pid, staffId);
            }
            return result;
        } else {
            if (staffId != null && !staffId.equals("")) {
                TblStaffMySql user;
                if (staffid != null) {
                    user = userService.findByMySqlId(staffid);
                } else {
                    user = userService.findByMySqlId(staffId);
                }

                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                BigDecimal orgid = staff.getCurrentOrg().getOrgid();
                List<TblRoleMySql> roles = tblRoleService.findAllMySql(orgid);
                List<TblJobMySql> findAll = tblJobService.findAllMySql(orgid);
                resultMap.put("roles", roles);
                resultMap.put("jobs", findAll);
                resultMap.put("user", user);
                JSONObject jsonObjectMV = new JSONObject(resultMap);
                result = jsonObjectMV.toString();

            } else {
                return this.userList(request, find, staffid, pageNumber, pageSize, token, pid, staffId);
            }
            return result;
        }
    }


    @RequestMapping(value = "/findOrganizationByTreeAllbm", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "公司及其下属部门")//组织架构-左侧列表
    public @ResponseBody
    String findOrganizationByTrees(BigDecimal nodeId, String type, HttpServletRequest request,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        //if (null == nodeId) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
//            TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
//            nodeId = organization.getOrgid();
            nodeId = staff.getCurrentOrg().getOrgid();
        //}
        String str;
        HashMap<String, Object> fields = new HashMap<String, Object>();
        fields.put("nodeId", nodeId);
        try {
            str = HttpClient.request(HttpClient.getDeptUrl, fields, null);
            if (!StringUtils.isNotBlank(str)) {
                List<Tree> list = this.tblOrganizaService.getNodeAllbm(nodeId);
                str = JSONObject.toJSONString(list);
            }
            return str;
        } catch (Exception e) {
            List<Tree> list = this.tblOrganizaService.getNodeAllbm(nodeId);
            str = JSONObject.toJSONString(list);
        }
        return str;
    }

    @RequestMapping(value = "/findOrganizationByJTTreeAll", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = " 公司及其下属公司")
    public @ResponseBody
    String findOrganizationByJTTree(BigDecimal nodeId, String type, HttpServletRequest request) {
        if (null == nodeId) {
            TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
            nodeId = organization.getOrgid();
        }
        String str;
        HashMap<String, Object> fields = new HashMap<String, Object>();
        fields.put("nodeId", nodeId);
        if (StringUtils.isNotBlank(type)) {
            try {
                str = HttpClient.request(HttpClient.getOrgChildrenUrl, fields, null);
                if (!StringUtils.isNotBlank(str)) {
                    List<Tree> list = this.tblOrganizaService.getJTTreeGS(nodeId);
                    str = JSONObject.toJSONString(list);
                }
                return str;
            } catch (Exception e) {
                List<Tree> list = this.tblOrganizaService.getJTTreeGS(nodeId);
                str = JSONObject.toJSONString(list);
            }
        } else {
            try {
                str = HttpClient.request(HttpClient.getOrgUrl, fields, null);
                if (!StringUtils.isNotBlank(str)) {
                    List<Tree> list = this.tblOrganizaService.getJTNodeAllGS(nodeId);
                    str = JSONObject.toJSONString(list);
                }
                return str;
            } catch (Exception e) {
                List<Tree> list = this.tblOrganizaService.getJTNodeAllGS(nodeId);
                str = JSONObject.toJSONString(list);
            }
        }
        return str;
    }

    @RequestMapping(value = "/org/listorg", method = {RequestMethod.POST})
    @ApiOperation(value = "机构管理-公司管理-列表+查询")
    public String listorg(HttpServletRequest request, Find find,
                          @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                          @ApiParam(name = "staffId", required = false) String staffId,
                          @ApiParam(name = "orgId", value = "组织ID", required = false) BigDecimal orgId,
                          @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch
    ) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            //   if (orgId == null || "".equals(orgId)) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (orgId == null) {
                orgId = staff.getCurrentOrg().getOrgid();
                ;
            }
            resultMap = tblOrganizaService.findAllCommpanyPageBeanGS(pageNumber, pageSize, staffId, token, find, orgId);
//        } else {
//            resultMap = tblOrganizaService.findAllCommpanyPageBeanGSXj(pageNumber, pageSize, staffId,find,token,orgId);
//        }

            JSONObject jsonObjectMAV = new JSONObject(resultMap);
            result = jsonObjectMAV.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (orgId == null) {
                orgId = staff.getCurrentOrg().getOrgid();
                ;
            }
            resultMap = tblOrganizaService.findAllMySqlCommpanyPageBeanGS(pageNumber, pageSize, staffId, token, find, orgId);
            JSONObject jsonObjectMAV = new JSONObject(resultMap);
            result = jsonObjectMAV.toString();
            return result;
        }
    }


    @RequestMapping(value = "/findOrganizationByJTTreeAllGS", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "机构管理-公司管理-左侧列表")
    public @ResponseBody
    String findOrganizationByJTTreeAllGS(String type, HttpServletRequest request,
                                         @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                         @ApiParam(name = "nodeId", required = false) BigDecimal nodeId,
                                         @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                         @ApiParam(name = "staffId", required = false) String staffId) {

        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (nodeId != null) {
            resultMap = tblOrganizaService.getJTNodeAll(pageNumber, pageSize, nodeId);
        } else {
            resultMap = tblOrganizaService.getJTTree(pageNumber, pageSize, token, staffId);
        }
        JSONObject jsonObjectMAV = new JSONObject(resultMap);
        result = jsonObjectMAV.toString();
        return result;
    }

    //这个接口是点击了公司列表Tree后出现在左侧的数据
    @RequestMapping(value = "/qxsd/listorg", method = {RequestMethod.POST})
    @ApiOperation(value = "菜单设定-右侧菜单列表")
    public String qxListorg(HttpServletRequest request,
                            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                            // @ApiParam(name = "staffId",required = false)String staffId,
                            @ApiParam(name = "pid", required = false) BigDecimal pid,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal staffId = staff.getStaffid();
        if (pid == null) {
            pid = staff.getCurrentOrg().getOrgid();
        }
        resultMap = tblOrganizaService.findAllCommpanyPageBean(pageNumber, pageSize, pid);
        JSONObject jsonObjectMAV = new JSONObject(resultMap);
        result = jsonObjectMAV.toString();
        return result;
    }

    @RequestMapping(value = "/org/hy_info", method = {RequestMethod.POST})
    @ApiParam("机构管理-行业架构-详情")
    public String orgHYInfo(HttpServletRequest request,
                            String orgid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            // String id = request.getParameter("orgid");
            TblOrganization org = tblOrganizaService.findById(orgid);
            // ModelAndView mv = new ModelAndView("common/zzjg/hy_organ_info");
            resultMap.put("org", org);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            TblOrganizationMySql org = tblOrganizaService.findByMySqlId(orgid);
            // ModelAndView mv = new ModelAndView("common/zzjg/hy_organ_info");
            resultMap.put("org", org);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    @RequestMapping(value = "/qx/qxInfo", method = {RequestMethod.POST})
    @ApiParam("用户权限管理-用户管理-详情")
    public String qxInfo(HttpServletRequest request,
                         BigDecimal staffid) {
        String result = null;
        try {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			    TblStaff org = tblStaffService.findByStaffid(staffid);
			    resultMap.put("org", org);
			    JSONObject jsonObjectMV = new JSONObject(resultMap);
			    result = jsonObjectMV.toString();
			    return result;
			} else {
			    TblStaffMySql org = tblStaffService.findByMySqlStaffid(staffid);
			    resultMap.put("org", org);
			    JSONObject jsonObjectMV = new JSONObject(resultMap);
			    result = jsonObjectMV.toString();
			    return result;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return result;
    }


    @RequestMapping(value = "/org/org_info", method = {RequestMethod.POST})
    @ApiParam("机构管理-菜单设定-菜单设定查看详情")
    public String org_info(HttpServletRequest request,
                           @ApiParam(name = "orgid", required = false) BigDecimal orgid) {
        //  String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return String.valueOf(tblOrganizaService.findByOrg(orgid));
//        JSONObject jsonObjectMV = new JSONObject(resultMap);
//        result = jsonObjectMV.toString();
//        return result;
        } else {
            return String.valueOf(tblOrganizaService.findByMySqlOrg(orgid));
        }
    }


    @RequestMapping(value = "/qxsd/screenRightList/qx_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiParam("用户授权功能")
    public @ResponseBody
    String qxsd_screenRightList_qx_save(HttpServletRequest reques,
                                        @RequestParam(value = "userid", required = false) String userid,
                                        @RequestParam(value = "priid", required = false) String priid) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(priid)) {
                TblStaff tblStaff = this.userService.findById(userid);
                if (null != tblStaff) {
                    this.tblManageScreenRightService.grantScreenRight(userid, priid);
                    return JsonBean.success();
                }
                return JsonBean.error("用户不存在");
            }
            return JsonBean.error();
        } else {
            if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(priid)) {
                TblStaffMySql tblStaff = this.userService.findByMySqlId(userid);
                if (null != tblStaff) {
                    this.tblManageScreenRightService.grantScreenRight(userid, priid);
                    return JsonBean.success();
                }
                return JsonBean.error("用户不存在");
            }
            return JsonBean.error();
        }
    }


    @RequestMapping(value = "/qxsd/list", method = {RequestMethod.POST})
    @ApiOperation(value = "权限设定-查询")
    public String qxList(HttpServletRequest request, Find find,
                         @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                         @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                         @ApiParam(name = "pid", required = false) BigDecimal pid,
                         @ApiParam(name = "staffId", required = false) String staffid,
                         @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (pid == null) {
                resultMap = userService.findAllPageBean(find, pageNumber, pageSize, token, staffid);
            } else {
                resultMap = userService.findAllPageBeanPid(staffid, find, pageNumber, pageSize, pid);
            }

            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            if (pid == null) {
                resultMap = userService.findAllMySqlPageBean(find, pageNumber, pageSize, token, staffid);
            } else {
                resultMap = userService.findAllMySqlPageBeanPid(staffid, find, pageNumber, pageSize, pid);
            }

            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }


    @RequestMapping(value = "/qxsd/qx_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "用户授权功能")
    public @ResponseBody
    String qx_save(
            @RequestParam(value = "userid", required = false) String userid,
            @RequestParam(value = "priid", required = false) String priid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(priid)) {
                TblStaff tblStaff = this.userService.findByUserId(userid);
                if (null != tblStaff) {
                    Jedis jedis = JedisUtil.getJedis();
                    tblManageRightService.grantScreenRight(userid, priid);

                    String listorgtreeJSON = RightCatch.getRightForUser(tblStaff.getStaffid().toString());
                    jedis.set(RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString(), listorgtreeJSON);
                    logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString() + "==value:" + jedis.get(RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString()));
                    JedisUtil.returnResource(jedis);
                    return JsonBean.success();
                }
                return JsonBean.error("用户不存在");
            }
            return JsonBean.error();
        } else {
            if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(priid)) {
                TblStaffMySql tblStaff = this.userService.findByMySqlUserId(userid);
                if (null != tblStaff) {
                    Jedis jedis = JedisUtil.getJedis();
                    tblManageRightService.grantScreenRight(userid, priid);

                    String listorgtreeJSON = RightCatch.getRightForUser(tblStaff.getStaffid().toString());
                    jedis.set(RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString(), listorgtreeJSON);
                    logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString() + "==value:" + jedis.get(RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString()));
                    JedisUtil.returnResource(jedis);
                    return JsonBean.success();
                }
                return JsonBean.error("用户不存在");
            }
            return JsonBean.error();
        }
    }

//    @PostMapping(value = "/qxsd/qx_save", produces = "application/json; charset=utf-8")
//    public @ResponseBody
//    String qx_save(@RequestParam(value = "userid", required = false) String userid,
//                   @RequestParam(value = "priid", required = false) String priid) {
//        logger.info("用户授权功能");
//        if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(priid)) {
//            TblStaff tblStaff = this.userService.findById(userid);
//            if (null != tblStaff) {
//                Jedis jedis = JedisUtil.getJedis();
//                List<TblManageRight> list = new ArrayList<TblManageRight>();
//                String[] priId = priid.split(",");
//                for (String pri : priId) {
//                    TblManageRight tmang = tblManageRightService.findById(pri);
//                    if (null != tmang) {
//                        list.add(tmang);
//                    }
//                }
//                //tblStaff.getTblManageRights().clear();
//                //tblStaff.getTblManageRights().addAll(list);
//                TblManageUserRight userRight = new TblManageUserRight();
//                for (TblManageRight userR : list) {
//                    userRight.setRightid(userR.getRightid());
//                    userRight.setStaffid(new BigDecimal(userid));
//                    tblManageRightService.inserUserRight(userRight);
//                }
//                tblStaffService.updateStaff(tblStaff);
//
//                String listorgtreeJSON = RightCatch.getRightForUser(tblStaff.getStaffid().toString());
//                jedis.set(RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString(), listorgtreeJSON);
//                logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString() + "==value:" + jedis.get(RedisFinalUtis.USERMANGERRIGHT + tblStaff.getStaffid().toString()));
//                JedisUtil.returnResource(jedis);
//                return JsonBean.success();
//            }
//            return JsonBean.error("用户不存在");
//        }
//        return JsonBean.error();
//    }


    @RequestMapping(value = "/qxsd/screenRightList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "报表授权功能")
    public @ResponseBody
    String qxsd_screenRightList(HttpServletRequest reques, Integer rightId,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffid", value = "登录用户主键", required = false) String staffid) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaff tblStaff = this.userService.findById(staffid);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();

            if (null != tblStaff) {
                String orgid = pid.toString();
                String treeJson = this.tblManageScreenRightService.getTree(tblStaff);
                //String treeJson =service.GetTreenew(staffid, orgid);
                return treeJson;
            }
            return null;
        } else {
            TblStaffMySql tblStaff = this.userService.findByMySqlId(staffid);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();

            if (null != tblStaff) {
                String orgid = pid.toString();
                TblStaff staff1 = new TblStaff();
                BeanUtils.copyProperties(tblStaff, staff1);
                String treeJson = this.tblManageScreenRightService.getTree(staff1);
                //String treeJson =service.GetTreenew(staffid, orgid);
                return treeJson;
            }
            return null;
        }
    }

    @RequestMapping(value = "/qxsd/mgnsq", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "用户权限管理-权限设定-权限设定（选定-选择，出功能授权）")
    public @ResponseBody
    String qx_gnsq(HttpServletRequest reques,
                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                   @ApiParam(name = "staffid", value = "登录用户主键", required = false) String staffid) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaff tblStaff = this.userService.findById(staffid);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (null != tblStaff) {
                Map<BigDecimal, Object> map = new HashMap<BigDecimal, Object>();
                List<TblManageRight> userRight = this.tblStaffService.findMansgeUserRight(staffid);
                for (TblManageRight tr : userRight) {
                    map.put(tr.getRightid(), 1);
                }
                String orgid = staff.getCurrentOrg().getOrgid().toString();
                String treeJson = tblManageRightService.GetTree(staffid, map, orgid);
                //String treeJson =tblManageRightService.GetTreenew(rightid, orgid);
                return treeJson;
            }
            return null;
        } else {
            TblStaffMySql tblStaff = this.userService.findByMySqlId(staffid);
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (null != tblStaff) {
                Map<BigDecimal, Object> map = new HashMap<BigDecimal, Object>();
                List<TblManageRightMySql> userRight = this.tblStaffService.findMySqlMansgeUserRight(staffid);
                for (TblManageRightMySql tr : userRight) {
                    map.put(tr.getRightid(), 1);
                }
                String orgid = staff.getCurrentOrg().getOrgid().toString();
                String treeJson = tblManageRightService.GetTree(staffid, map, orgid);
                //String treeJson =tblManageRightService.GetTreenew(rightid, orgid);
                return treeJson;
            }
            return null;
        }
    }


    @RequestMapping(value = "/zt/index", method = {RequestMethod.POST})
    @ApiOperation(value = "下级公司授权-主页")
    public String zt_index(HttpServletRequest request) {
        String result = null;
        ModelAndView mv = new ModelAndView("common/gsgl/zt_list");
        Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问数据成功"));
        JSONObject jsonObjectmv = new JSONObject(resultMap);
        result = jsonObjectmv.toString();
        return result;
    }

    @RequestMapping(value = "/zt/leftlist", method = {RequestMethod.POST})
    @ApiOperation(value = "查询公司左侧tree的数据")
    public String zt_leftlist(HttpServletRequest request) {
        String result = null;
        ModelAndView mv = new ModelAndView("common/gsgl/zt_left");
        Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问数据成功"));
        JSONObject jsonObjectMv = new JSONObject(resultMap);
        result = jsonObjectMv.toString();
        return result;
    }

    @RequestMapping(value = "/zt/listorg", method = {RequestMethod.POST})
    @ApiOperation(value = "查询公司的数据")
    public String zt_listorg(HttpServletRequest request,
                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @ApiParam(name = "pid", required = false) BigDecimal pid,
                             @ApiParam(name = "staffId", required = false) String staffId
    ) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        resultMap = tblAcctBookService.findByTypeNewZB(token, pageNumber, pageSize, pid);

        JSONObject jsonObjectMav = new JSONObject(resultMap);
        result = jsonObjectMav.toString();
        return result;
    }


    @RequestMapping(value = "/reportlist", method = {RequestMethod.POST})
    @ApiOperation(value = "主题仓库一级菜单列表")
    public String biReportMenu(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                               @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                               @RequestParam(name = "orgid", required = false) String orgid,
                               @RequestParam(name = "pid", required = false) String pid,
                               @RequestParam(name = "type", required = false) String type) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        PageBean pageBean = new PageBean();
        try {
            resultMap = tblOrganizaService.finreportMenuList(pageNumber, pageSize, StringUtil.isNullOrEmpty(pid) ? type : pid, token, orgid);

        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            resultMap.put("pageBean", pageBean);
            resultMap.put("type", type);
        }
        JSONObject jsonObjectMav = new JSONObject(resultMap);
        result = jsonObjectMav.toString();
        return result;

    }


    @RequestMapping(value = "/zt_user/newlist", method = {RequestMethod.POST})
    @ApiOperation(value = "账套授权(点了选择出现的框框【点了左侧列表后，右侧列表出现数据】)")
    public String userNewListss(HttpServletRequest request, String acctid, String page,
                                String pid, String type,
                                @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", required = false) String staffId) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        Jedis jedis = null;
        if (type != null && type.length() > 0) {
            request.getSession().setAttribute("userType", type);
        }
        if (type != null && type.equals("''")) {
            type = null;
        }

        if (pid != null && pid.trim().length() != 0) {
            resultMap = tblStaffService.findByAll(pid, pageNumber, pageSize, token, staffId);
        } else {
            resultMap = tblStaffService.findAllPageBean(pageNumber, pageSize, token, staffId);
        }
        //resultMap.put("orgid",orgid);
        resultMap.put("pid", pid);
        resultMap.put("type", type);
        resultMap.put("acctid", acctid);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;

    }

    @RequestMapping(value = "/zt/saveNewAccBookManage", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "账套授权（点击选定后的接口）")
    public @ResponseBody
    String saveNewAccBookManage(HttpServletRequest request,
                                @RequestParam(value = "acctid", required = false) String acctid,
                                @RequestParam(value = "staffid", required = false) String staffid,
                                @RequestParam(value = "orgid", required = false) String orgid,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (StringUtils.isNotBlank(staffid)) {
                Set<TblManageUserBook> userBookList = new HashSet<TblManageUserBook>();
                List<TblAccBook> bookList = new ArrayList<TblAccBook>(0);
                //TblManageUserBook userBook = null;
                TblManageUserBook bookId = null;
                String[] acctids = acctid.split(",");
                String[] staffids = staffid.split(",");
                for (String pri : acctids) {
                    if (pri.trim().length() != 0) {
                        for (int i = 0; i < staffids.length; i++) {
                            bookId = new TblManageUserBook();
                            bookId.setBookid(pri);
                            bookId.setStaffid(new BigDecimal(staffids[i]));
                            userBookList.add(bookId);
                        }
                    }
                }

                tblManageUserBookservice.updateUserBook(userBookList, orgid, staffid);
                List<TblAccBook> tablist = tblAccBookService.findBookIdByUserAll(staff.getStaffid(), staff.getCurrentOrg().getOrgid());
                List<TblAccBook> books = DepartmentUtils.getAllDepartmentss(tablist);
                request.getSession().setAttribute("tablist", books);
                return JsonBean.success();
            }
            return JsonBean.error("请选择");
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (StringUtils.isNotBlank(staffid)) {
                Set<TblManageUserBookMySql> userBookList = new HashSet<TblManageUserBookMySql>();
                List<TblAccBookMySql> bookList = new ArrayList<TblAccBookMySql>(0);
                //TblManageUserBook userBook = null;
                TblManageUserBookMySql bookId = null;
                String[] acctids = acctid.split(",");
                String[] staffids = staffid.split(",");
                for (String pri : acctids) {
                    if (pri.trim().length() != 0) {
                        for (int i = 0; i < staffids.length; i++) {
                            bookId = new TblManageUserBookMySql();
                            bookId.setBookid(pri);
                            bookId.setStaffid(new BigDecimal(staffids[i]));
                            userBookList.add(bookId);
                        }
                    }
                }
                tblManageUserBookservice.updateMySqlUserBook(userBookList, orgid, staffid);
                List<TblAccBookMySql> tablist = tblAccBookService.findBookIdByMySqlUserAll(staff.getStaffid(), staff.getCurrentOrg().getOrgid());
                List<TblAccBookMySql> books = DepartmentUtils.getAllMySqlDepartmentss(tablist);
                request.getSession().setAttribute("tablist", books);
                return JsonBean.success();
            }
            return JsonBean.error("请选择");
        }
    }


    @RequestMapping(value = "/user/zbqxindexs", method = {RequestMethod.POST})
    @ApiOperation(value = "账簿数据取消授权，查询用户信息")
    public String zbqxindexs(HttpServletRequest request,
                             @RequestParam(value = "acctid", required = true) String acctid,
                             @RequestParam(value = "realname", required = false) String realname,
                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            PageInfo<TblStaff> pageInfo = new PageInfo<TblStaff>();
            try {
                TblStaff staff = new TblStaff();
                staff.setOrgid(user.getCurrentOrg().getOrgid());
                if (realname != null && realname.trim().length() != 0) {
                    staff.setRealname(realname);
                }
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setCondition(staff);
                pageInfo.setSqlStr(acctid);
                Map<String, Object> resultMap = tblStaffService.findUserByZbsjForQx(pageInfo);
                JSONObject jsonObjectMv = new JSONObject(resultMap);
                result = jsonObjectMv.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            PageInfo<TblStaffMySql> pageInfo = new PageInfo<TblStaffMySql>();
            try {
                TblStaffMySql staff = new TblStaffMySql();
                staff.setOrgid(user.getCurrentOrg().getOrgid());
                if (realname != null && realname.trim().length() != 0) {
                    staff.setRealname(realname);
                }
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setCondition(staff);
                pageInfo.setSqlStr(acctid);
                Map<String, Object> resultMap = tblStaffService.findUserByMySqlZbsjForQx(pageInfo);
                JSONObject jsonObjectMv = new JSONObject(resultMap);
                result = jsonObjectMv.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @RequestMapping(value = "/zt/delAccBookManage", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "套账授权-用户账套授权取消功能")
    public @ResponseBody
    String delAccBookManage(@RequestParam(value = "sid", required = false) String sid,
                            @RequestParam(value = "acctid", required = false) String acctid,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                //logger.info("取消用户账套授权");
                tblManageUserBookservice.delUserBook(sid, acctid);
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                List<TblAccBook> bookList = tblAccBookService.findBookIdByUserAll(staff.getStaffid(), staff.getCurrentOrg().getOrgid());
                List<TblAccBook> books = DepartmentUtils.getAllDepartmentss(bookList);
                request.getSession().setAttribute("tablist", books);
                return JsonBean.success();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return JsonBean.error();
        } else {
            try {
                //logger.info("取消用户账套授权");
                tblManageUserBookservice.delUserBook(sid, acctid);
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                List<TblAccBookMySql> bookList = tblAccBookService.findBookIdByMySqlUserAll(staff.getStaffid(), staff.getCurrentOrg().getOrgid());
                List<TblAccBookMySql> books = DepartmentUtils.getAllMySqlDepartmentss(bookList);
                request.getSession().setAttribute("tablist", books);
                return JsonBean.success();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return JsonBean.error();
        }
    }

    /**
     * 账套授权-查看详情
     *
     * @param request
     * @param pageNumber
     * @param pageSize
     * @param bookid
     * @param pid
     * @return
     */
    @RequestMapping(value = "/zt/accbookdetail", method = {RequestMethod.POST})
    @ApiOperation(value = "账套授权-查看详情")
    public String accbookdetail(HttpServletRequest request,
                                @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                @RequestParam(value = "bookid", required = false) String bookid,
                                @RequestParam(value = "pid", required = false) String pid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            PageInfo<TblStaff> pageInfo = new PageInfo<>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            userService.findAllPageInfoByacctid(pageInfo, bookid);

            resultMap.put("pid", pid);
            resultMap.put("bookid", bookid);
            resultMap.put("pageInfo", pageInfo);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            PageInfo<TblStaffMySql> pageInfo = new PageInfo<>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            userService.findAllMySqlPageInfoByacctid(pageInfo, bookid);

            resultMap.put("pid", pid);
            resultMap.put("bookid", bookid);
            resultMap.put("pageInfo", pageInfo);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    @RequestMapping(value = "/sjzyk_nbzj", method = {RequestMethod.POST})
    @ApiOperation(value = "内部专家资源库列表")
    public String sjzyk_nbzj(HttpServletRequest request, Find find,
                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId
    ) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = this.tblInteriorExpertService.getExperList(find, staffId, pageNumber, pageSize, token);
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        } else {
            Map<String, Object> resultMap = this.tblInteriorExpertService.getMySqlExperList(find, staffId, pageNumber, pageSize, token);
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        }
    }


    @RequestMapping(value = "/sjzyk_wpzj", method = {RequestMethod.POST})
    @ApiOperation(value = "外聘专家资源库列表")
    public String sjzyk_wpzj(HttpServletRequest request, Find find, String company,
                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = this.tblExternalExpertService.findByOrgId(find, pageNumber, pageSize, token, staffId, company);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            Map<String, Object> resultMap = this.tblExternalExpertService.findByMySqlOrgId(find, pageNumber, pageSize, token, staffId, company);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }


//    @RequestMapping(value = "/nbzj_to_add", method = {RequestMethod.POST})
//    @ApiOperation(value = "内部专家  新增 or 修改 跳转")
//    public String nbzj_to_add(HttpServletRequest request, TblInteriorExpert interior) {
//        String oid = request.getParameter("oid");
//        ModelAndView mv = new ModelAndView();
//        Map<String,Object> resultMap = new HashMap<String,Object>(0);
//        if (interior != null) {
//            TblInteriorExpert expert = this.tblInteriorExpertService.findInterior(interior);
//            mv.addObject("expert", expert);
//        }
//        //为页面查找区域显隐藏赋值
//        String choiceSearch = request.getParameter("choiceSearch");
//        if(choiceSearch == null || "".equals(choiceSearch)) {
//            choiceSearch = "hide";
//        }
//        resultMap.put("choiceSearch", choiceSearch );
//        resultMap.put("msg","访问成功");
//        String result = null;
//        JSONObject jsonObjectmv = new JSONObject(resultMap);
//        result = jsonObjectmv.toString();
//        return result;
//    }


    @RequestMapping(value = "/nbzj_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "内部专家  新增  or 修改")
    public @ResponseBody
    String nbzj_save(HttpServletRequest request, BigDecimal userid, TblInteriorExpert interiorExpert,
                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                     @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        BigDecimal orgid;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            if (null != userid) {
                TblStaff tblStaff = this.tblStaffService.get(userid);
                if (tblStaff != null) {
                    //TODO
                    if (interiorExpert.getInteriorid() == null) {
                        interiorExpert.setOrgId(pid);
                        interiorExpert.setStaffid(tblStaff.getStaffid());
                        this.tblInteriorExpertService.save(interiorExpert);
                    } else {
                        tblInteriorExpertService.update(interiorExpert);
                    }
                    return JsonBean.success();
                }
            }
            return JsonBean.success();
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal pid = staff.getCurrentOrg().getOrgid();
            if (null != userid) {
                TblStaffMySql tblStaff = this.tblStaffService.getMySql(userid);
                if (tblStaff != null) {
                    //TODO
                    if (interiorExpert.getInteriorid() == null) {
                        interiorExpert.setOrgId(pid);
                        interiorExpert.setStaffid(tblStaff.getStaffid());
                        this.tblInteriorExpertService.saveMySql(interiorExpert);
                    } else {
                        tblInteriorExpertService.updateMySql(interiorExpert);
                    }
                    return JsonBean.success();
                }
            }
            return JsonBean.success();
        }
    }


    @RequestMapping(value = "/nbzj_del", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "内部专家库-删除")
    public @ResponseBody
    String nbzj_save(HttpServletRequest request, BigDecimal interiorid) {
//                                          @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token,
//                                          @ApiParam(name="staffId",value="登录用户ID",required=false)String staffId

        String result = null;
        try {
            Map<String, Object> resultMap = this.tblInteriorExpertService.removeNbzj(interiorid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;

    }


    @RequestMapping(value = "/sjzjk_to_add", method = {RequestMethod.POST})
    @ApiOperation(value = "外聘专家库-添加")
    public String sjzjk_to_add(HttpServletRequest request, BigDecimal exterid,
                               @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        //String oid = request.getParameter("oid");
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil tblstaff = DealUserToken.parseUserToken(token);
            BigDecimal pid = tblstaff.getCurrentOrg().getOrgid();
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            if (exterid != null) {
                TblExternalExpert expert = tblExternalExpertService.getExpert(exterid);
                TblStaff staff = tblStaffService.getExpert(expert.getStaffid());
                resultMap.put("expert", expert);
                resultMap.put("staff", staff);
            }
            resultMap.put("pid", pid);
            String result = null;
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        } else {
            TblStaffUtil tblstaff = DealUserToken.parseUserToken(token);
            BigDecimal pid = tblstaff.getCurrentOrg().getOrgid();
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            if (exterid != null) {
                TblExternalExpertMySql expert = tblExternalExpertService.getMySqlExpert(exterid);
                TblStaffMySql staff = tblStaffService.getMySqlExpert(expert.getStaffid());
                resultMap.put("expert", expert);
                resultMap.put("staff", staff);
            }
            resultMap.put("pid", pid);
            String result = null;
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        }
    }


    @RequestMapping(value = "/sjzjk_add", method = {RequestMethod.POST})
    @ApiOperation(value = "外聘专家库-添加")
    public String sjzjk_add(HttpServletRequest request, TblStaff user, TblExternalExpert tee,
                            @ApiParam(name = "oid", value = "oid", required = true) String oid,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token
    ) throws Exception {
        //boolean is = false;
//
//        TblStaffUtil tblstaff = DealUserToken.parseUserToken(token);
//        //BigDecimal orgid = tblstaff.getCurrentOrg().getOrgid();
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (tee != null && tee.getExterid() != null) {
                tblExternalExpertService.updateTblExternalExpert(tee);
                TblStaff staff = tblStaffService.get(tee.getStaffid());
                staff.setUsername(user.getUsername());
                staff.setRealname(user.getRealname());
                staff.setEmail(user.getEmail());
                staff.setMiblephone(user.getMiblephone());
                staff.setStatus(user.getStatus());
                tblStaffService.modifyStaff(staff);
                // is = true;
            } else {
                //TblOrganization org = tblOrganizaService.findByoId(new BigDecimal(oid));
                user.setOrgid(new BigDecimal(oid));
                user.setPassword(MD5Encrypt.encrypByMd5(user.getPassword()));
                tblStaffService.add(user);
                tee.setStaffid(user.getStaffid());
                tblExternalExpertService.saveTblExternalExpert(tee);
            }

            return JsonBean.success();
        } else {
            if (tee != null && tee.getExterid() != null) {
                TblExternalExpertMySql teeMySql = new TblExternalExpertMySql();
                BeanUtils.copyProperties(tee, teeMySql);
                tblExternalExpertService.updateMySqlTblExternalExpert(teeMySql);
                TblStaffMySql staff = tblStaffService.getMySql(tee.getStaffid());
                staff.setUsername(user.getUsername());
                staff.setRealname(user.getRealname());
                staff.setEmail(user.getEmail());
                staff.setMiblephone(user.getMiblephone());
                staff.setStatus(user.getStatus());
                tblStaffService.modifyMySqlStaff(staff);
                // is = true;
            } else {
                //TblOrganization org = tblOrganizaService.findByoId(new BigDecimal(oid));
                user.setOrgid(new BigDecimal(oid));
                user.setPassword(MD5Encrypt.encrypByMd5(user.getPassword()));
                TblStaffMySql userMySql = new TblStaffMySql();
                BeanUtils.copyProperties(user, userMySql);
                TblExternalExpertMySql teeMySql = new TblExternalExpertMySql();
                BeanUtils.copyProperties(tee, teeMySql);
                tblStaffService.addMySql(userMySql);
                tee.setStaffid(user.getStaffid());
                tblExternalExpertService.saveMySqlTblExternalExpert(teeMySql);
            }

            return JsonBean.success();
        }
    }


    @RequestMapping(value = "/addReportMenuView", method = {RequestMethod.POST})
    @ApiOperation(value = "主题仓库-主题展示-跳主题添加修改页面")
    public String addReportMenuView(String id, String pid, String type,
                                    @RequestParam(value = "leveltype", required = false) String leveltype) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            String result = null;
            if (!id.equals("") & id != null) {
                TblBiReportMenu tblBiReportMenu = new TblBiReportMenu();
                TblOrganization or = new TblOrganization();
                try {
                    tblBiReportMenu = tblBiReportMenuService.geTblBiReportMenu(id);
                    or = tblOrganizaService.findById(tblBiReportMenu.getUnit());
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    resultMap.put("tbp", tblBiReportMenu);
                    resultMap.put("orgname", or.getOrgname());
                    resultMap.put("pid", tblBiReportMenu.getPageid());
                    resultMap.put("a", tblBiReportMenu.getTblAttachments());
                    resultMap.put("type", type);
                    resultMap.put("msg", "访问成功");
                }

            } else {
                TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
                resultMap.put("msg", "访问成功");
                resultMap.put("org", attribute1);
                //当新增主题为一级菜单式leveltype为null,二级菜单leveltype为0；用来判断新增的是一级主题还二级主题
                if (leveltype != null && leveltype.trim().length() != 0) {
                    resultMap.put("level", 0);
                } else {
                    resultMap.put("level", 1);
                }
                resultMap.put("pid", pid);
                resultMap.put("type", type);
            }
            JSONObject jsonObjMv = new JSONObject(resultMap);
            result = jsonObjMv.toString();

            return result;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            String result = null;
            if (!id.equals("") & id != null) {
                TblBiReportMenuMySql tblBiReportMenu = new TblBiReportMenuMySql();
                TblOrganizationMySql or = new TblOrganizationMySql();
                try {
                    tblBiReportMenu = tblBiReportMenuService.geMySqlTblBiReportMenu(id);
                    or = tblOrganizaService.findByMySqlId(tblBiReportMenu.getUnit());
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    resultMap.put("tbp", tblBiReportMenu);
                    resultMap.put("orgname", or.getOrgname());
                    resultMap.put("pid", tblBiReportMenu.getPageid());
                    resultMap.put("a", tblBiReportMenu.getTblAttachments());
                    resultMap.put("type", type);
                    resultMap.put("msg", "访问成功");
                }

            } else {
                TblOrganizationMySql attribute1 = (TblOrganizationMySql) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
                resultMap.put("msg", "访问成功");
                resultMap.put("org", attribute1);
                //当新增主题为一级菜单式leveltype为null,二级菜单leveltype为0；用来判断新增的是一级主题还二级主题
                if (leveltype != null && leveltype.trim().length() != 0) {
                    resultMap.put("level", 0);
                } else {
                    resultMap.put("level", 1);
                }
                resultMap.put("pid", pid);
                resultMap.put("type", type);
            }
            JSONObject jsonObjMv = new JSONObject(resultMap);
            result = jsonObjMv.toString();

            return result;
        }
    }

    @RequestMapping(value = "/page_byNum", method = {RequestMethod.POST})
    public @ResponseBody
    String page_byNum(HttpServletRequest request) {
        String code = request.getParameter("code");
        return tblBiReportMenuService.isExistBiPageCode(code).toString();
    }


    @RequestMapping(value = "/addReportMenu", method = {RequestMethod.POST})
    @ApiOperation(value = "主题仓库-主题展示-新建(同手机主题新建)修改")
    public String addReportMenu(TblBiReportMenu menu,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                                @ApiParam(name = "unit", required = false) String unit) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                if (menu.getPageid() != null) {
                    TblBiReportMenu page = tblBiReportMenuService.geTblBiReport(menu.getPageid());
                    page.setUnit(unit);
                    page.setPagecode(menu.getPagecode());
                    page.setPagename(menu.getPagename());
                    page.setMemo1(menu.getMemo1());
                    page.setUrl(menu.getUrl());
                    page.setPageDes(menu.getPageDes());
                    if (menu.getType() == null) {
                        menu.setType("0");
                    }
                    page.setType(menu.getType());
                    page.setRqurl(menu.getRqurl());
                    tblBiReportMenuService.updateReportMenu(menu);

                } else {
                    TblStaffUtil staff = DealUserToken.parseUserToken(token);
                    BigDecimal orgid = staff.getCurrentOrg().getOrgid();
                    menu.setUnit(orgid.toString());
                    menu.setCreatedate(new Date());
                    menu.setRightid(new BigDecimal(194));
                    if (menu.getType() == null) {
                        menu.setType("0");
                    }
                    menu.setMemo2("0");
                    if (menu.getPid() != null) {
                        menu.setPagebody(new BigDecimal(menu.getPid()));
                    }
                    tblBiReportMenuService.saveReportMenu(menu);
                }

            } catch (Exception e) {
                System.out.println("主题菜单添加失败！");
                e.printStackTrace();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", "成功");
            JSONObject jsonObjMv = new JSONObject(resultMap);
            result = jsonObjMv.toString();

            return result;
        } else {
            try {
                if (menu.getPageid() != null) {
                    TblBiReportMenuMySql page = tblBiReportMenuService.geMySqlTblBiReport(menu.getPageid());
                    page.setUnit(unit);
                    page.setPagecode(menu.getPagecode());
                    page.setPagename(menu.getPagename());
                    page.setMemo1(menu.getMemo1());
                    page.setUrl(menu.getUrl());
                    page.setPageDes(menu.getPageDes());
                    if (menu.getType() == null) {
                        menu.setType("0");
                    }
                    page.setType(menu.getType());
                    page.setRqurl(menu.getRqurl());
                    TblBiReportMenuMySql menuMySql = new TblBiReportMenuMySql();
                    BeanUtils.copyProperties(menu, menuMySql);
                    tblBiReportMenuService.updateMySqlReportMenu(menuMySql);

                } else {
                    TblStaffUtil staff = DealUserToken.parseUserToken(token);
                    BigDecimal orgid = staff.getCurrentOrg().getOrgid();
                    menu.setUnit(orgid.toString());
                    menu.setCreatedate(new Date());
                    menu.setRightid(new BigDecimal(194));
                    if (menu.getType() == null) {
                        menu.setType("0");
                    }
                    menu.setMemo2("0");
                    if (menu.getPid() != null) {
                        menu.setPagebody(new BigDecimal(menu.getPid()));
                    }
                    TblBiReportMenuMySql menuMySql = new TblBiReportMenuMySql();
                    BeanUtils.copyProperties(menu, menuMySql);
                    tblBiReportMenuService.saveMySqlReportMenu(menuMySql);
                }

            } catch (Exception e) {
                System.out.println("主题菜单添加失败！");
                e.printStackTrace();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", "成功");
            JSONObject jsonObjMv = new JSONObject(resultMap);
            result = jsonObjMv.toString();

            return result;
        }
    }

    @RequestMapping(value = "/moduleDistributio", method = {RequestMethod.POST})
    @ApiOperation(value = "主题展示 打开模块下发页面")
    public String moduleDistribution(HttpServletRequest request,
                                     @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     @RequestParam(value = "ids", required = false) String ids, TblManageRight right,
                                     @RequestParam(value = "cztype", required = false) String cztype,
                                     @RequestParam(value = "pid", required = false) String pid,
                                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                     @ApiParam(name = "staffId", required = false) String staffId) throws Exception {
        //TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选则的机构
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal attribute = staff.getCurrentOrg().getOrgid();

            try {
                PageInfo<TblManageRight> pageInfo = new PageInfo<TblManageRight>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setCondition(right);
                this.tblManageRightService.findRightListBiDistribution(pageInfo, attribute);

                resultMap.put("ids", ids);
                resultMap.put("pageInfo", pageInfo);
                resultMap.put("cztype", cztype);
                resultMap.put("pid", pid);
            } catch (Exception e) {
                e.printStackTrace();
            }

            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            BigDecimal attribute = staff.getCurrentOrg().getOrgid();
            TblManageRightMySql rightMySql = new TblManageRightMySql();
            BeanUtils.copyProperties(right, rightMySql);
            try {
                PageInfo<TblManageRightMySql> pageInfo = new PageInfo<TblManageRightMySql>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setCondition(rightMySql);
                this.tblManageRightService.findMySqlRightListBiDistribution(pageInfo, attribute);

                resultMap.put("ids", ids);
                resultMap.put("pageInfo", pageInfo);
                resultMap.put("cztype", cztype);
                resultMap.put("pid", pid);
            } catch (Exception e) {
                e.printStackTrace();
            }

            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @RequestMapping(value = "/chooseRithgId/disPageId", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "A模块下发报表")
    public String chooseRithgIdDisPageId(Model model, HttpServletRequest request,
                                         @RequestParam(value = "rightids", required = true) String[] rightids,
                                         @RequestParam(value = "pageids", required = true) String[] pageids,
                                         @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                         @ApiParam(name = "staffId", required = false) String staffId) throws Exception {
//        TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选则的机构
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal orgid = staff.getCurrentOrg().getOrgid();

        try {
            this.tblManageRightService.distributionPageIdByRightId(rightids, pageids, orgid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        resultMap.put("code", 1);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    @RequestMapping(value = "/chooseRithgId/disPageIdTwo", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "B模块下发报表")
    public String chooseRithgIdDisPageIdTwo(Model model, HttpServletRequest request,
                                            @RequestParam(value = "rightids", required = true) String[] rightids,
                                            @RequestParam(value = "pageids", required = true) String[] pageids,
                                            @RequestParam(value = "pid", required = true) String pid,
                                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                            @ApiParam(name = "staffId", required = false) String staffId) throws Exception {
        //TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选则的机构
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal attribute = staff.getCurrentOrg().getOrgid();
        try {
            this.tblManageRightService.distributionPageIdByRightIdTwo(rightids, pageids, attribute, pid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "0";
    }


    @RequestMapping(value = "/user/indexs", method = {RequestMethod.POST})
    @ApiOperation(value = "选择用户")
    public String userIndex(HttpServletRequest request,
                            @RequestParam(value = "id", required = false) String id,
                            @RequestParam(value = "start", required = false) String start,
                            @RequestParam(value = "num", required = false) String num) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (start != null) {
                List<String> pageNameList = new ArrayList<String>();
                TblBiReportMenu geTblBiReportMenu = null;
                for (int i = 0; i < id.length(); i++) {
                    geTblBiReportMenu = this.tblBiReportMenuService.geTblBiReportMenu(id);
                    //  pageNameList.add(geTblBiReportMenu.getPagename());
                }
                resultMap.put("pageNameList", geTblBiReportMenu);
            }
            //String num = request.getParameter("type");
            resultMap.put("type", num);
            resultMap.put("selectM", request.getParameter("selectM"));
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        } else {
            if (start != null) {
                List<String> pageNameList = new ArrayList<String>();
                TblBiReportMenuMySql geTblBiReportMenu = null;
                for (int i = 0; i < id.length(); i++) {
                    geTblBiReportMenu = this.tblBiReportMenuService.geMySqlTblBiReportMenu(id);
                    //  pageNameList.add(geTblBiReportMenu.getPagename());
                }
                resultMap.put("pageNameList", geTblBiReportMenu);
            }
            //String num = request.getParameter("type");
            resultMap.put("type", num);
            resultMap.put("selectM", request.getParameter("selectM"));
            JSONObject jsonObjectMv = new JSONObject(resultMap);
            result = jsonObjectMv.toString();
            return result;
        }
    }

    @ApiOperation(value = "集团版 --数据控制（内部专家添加时内部单选人接口）")
    @RequestMapping(value = "/findOrganizationByTreeAll", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String findOrganizationByTree(BigDecimal nodeId, String type, BigDecimal orgId
            , @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                  HttpServletRequest request,
                                  @RequestParam(value = "str", required = false) String str) throws Exception {
        String json = "";
        // String str = request.getParameter("str");
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        if (null == nodeId) {
            nodeId = orgId;
            if (null == orgId) {
                //TblStaff tblStaff = (TblStaff) request.getSession().getAttribute("longUser");
                nodeId = staff.getCurrentOrg().getOrgid();
            }
        }
        if (StringUtils.isNotBlank(type)) {
            List<Tree> list = this.tblOrganizaService.getTree(nodeId);
            for (Tree tree : list) {
                if (!tree.getIsParent()) {
                    tree.setTarget("mainFramex");
                    tree.setUrl("/nbsj/user/list?type=" + str + "&pid=" + tree.getId());
                }
            }
            json = JSONObject.toJSONString(list);
        } else {
            // 修改前 Tree tree = this.tblOrganizaService.getTreeRoot(nodeId);
            //tyb修改 项目管理--/项目经理展开左侧树
            List<Tree> list = this.tblOrganizaService.getNodeAll(nodeId);
            for (Tree tree : list) {
                setUrlByTree(tree, "/nbsj/user/list?type=" + str + "&pid=");
            }
            json = JSONObject.toJSONString(list);
        }
        return json;
    }

    private void setUrlByTree(Tree tree, String url) {
        for (Tree tre : tree.getChildren()) {
            if (tre.getChildren().size() > 0) {
                setUrlByTree(tre, url);
            }
            // if (!tre.getIsParent()) {
            tre.setTarget("mainFramex");
            tre.setUrl(url + tre.getId());
            //}
        }
    }


    @RequestMapping(value = "/page_del", method = {RequestMethod.POST})
    @ApiOperation(value = "主题菜单-删除")
    public String page_del(HttpServletRequest request, BigDecimal selectedId,
                           String orgid, String type, String flag) {
        tblBiCkEchartsService.delete(selectedId);
        tblBiReportMenuService.deleteReportMenuPageId(selectedId);
        return JsonBean.success();

    }

    @RequestMapping(value = "/issudeUser", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "下发到个人")
    public @ResponseBody
    String issuedUser(
            @RequestParam(value = "id", required = false) String id,
            @RequestParam(value = "userid", required = false) String userid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        //String resulte="";
        //获取Spring容器中的的Service
//        UserService service = (UserService) SpringContextHolder.getBean("UserService");
        //根据用户名查询用户
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblManageRight mr = new TblManageRight();
            //这个表没有用但是必须有数据，默认给一个菜单有数据的ID就好
            mr.setRightid(new BigDecimal(194));
            try {
                String[] ids = id.split(",");
                for (String idStr : ids) {
                    String[] users = userid.split(",");
                    for (String string : users) {
                        TblStaff user = tblStaffService.findById(string);
                        //根据父id查询一级主题菜单
                        TblBiReportMenu menu = this.tblBiReportMenuService.selectTblBiReportMenu(idStr);
                        //给用户主题表赋值
                        TblBiReportMenu page = new TblBiReportMenu();
                        page.setCreatedate(new Date());
                        page.setCreater(user.getUsername());
                        page.setForbidden(menu.getForbidden());
                        page.setMemo1(menu.getMemo1());
                        page.setMemo2(menu.getMemo2());
                        page.setPagecode(menu.getPagecode());
                        page.setPageDes(menu.getPageDes());
                        page.setPagename(menu.getPagename());
                        page.setPageuser(menu.getPageuser());
                        page.setRqurl(menu.getRqurl());
                        page.setRightid(new BigDecimal(194));
                        page.setTreeid(new BigDecimal(string));
                        page.setUnit(user.getOrgid().toString());
                        page.setType(menu.getType());
                        tblBiReportMenuService.addPage(page);

                        //根据id查询二级主题菜单
                        List<TblBiReportMenu> findByFatherid = this.tblBiReportMenuService.selectByFatherid(idStr);

                        for (TblBiReportMenu tblBiReportMenu : findByFatherid) {
                            TblBiReportMenu pagetow = new TblBiReportMenu();
                            pagetow.setCreatedate(new Date());
                            pagetow.setCreater(user.getUsername());
                            pagetow.setForbidden(tblBiReportMenu.getForbidden());
                            pagetow.setMemo1(tblBiReportMenu.getMemo1());
                            pagetow.setMemo2(tblBiReportMenu.getMemo2());
                            pagetow.setPagecode(tblBiReportMenu.getPagecode());
                            pagetow.setPageDes(tblBiReportMenu.getPageDes());
                            pagetow.setPagename(tblBiReportMenu.getPagename());
                            pagetow.setPageuser(tblBiReportMenu.getPageuser());
                            pagetow.setRqurl(tblBiReportMenu.getRqurl());
                            pagetow.setRightid(new BigDecimal(194));
                            pagetow.setTreeid(new BigDecimal(string));
                            pagetow.setUnit(user.getOrgid().toString());
                            pagetow.setPagebody(page.getPageid());
                            tblBiReportMenuService.addPage(pagetow);
                            if (tblBiReportMenu.getRqurl() == null) {
                                //查询主题图表，添加
                                List<TblBiCkEcharts> chartsPages = tblBiCkEchartsService
                                        .getChartsPages(tblBiReportMenu.getPageid().toString());
                                for (TblBiCkEcharts charts : chartsPages) {
                                    TblBiChart biChart = new TblBiChart();
                                    biChart.setTitle(charts.getTitle());
                                    biChart.setAxisx(charts.getAxisx());
                                    biChart.setAxisy(charts.getAxisy());
                                    biChart.setChartname(charts.getChartname());
                                    biChart.setCharttype(charts.getCharttype());
                                    biChart.setMemo(charts.getMemo());
                                    biChart.setPointx(charts.getPointx());
                                    biChart.setPointy(charts.getPointy());
                                    biChart.setWidth(charts.getWidth());
                                    biChart.setHeight(charts.getHeight());
                                    biChart.setPageType(charts.getPageType());
                                    //添加图表
                                    tblBiChartService.add(biChart);

                                }
                            }
                        }

                    }
                    resultMap.put("code", "1");

                    JSONObject jsonObjectMav = new JSONObject(resultMap);
                    result = jsonObjectMav.toString();
                    return result;
                }
            } catch (Exception e) {

                e.printStackTrace();

            } finally {
                resultMap.put("code", "1");

                JSONObject jsonObjectMav = new JSONObject(resultMap);
                result = jsonObjectMav.toString();
                return result;
            }
        } else {
            TblManageRightMySql mr = new TblManageRightMySql();
            //这个表没有用但是必须有数据，默认给一个菜单有数据的ID就好
            mr.setRightid(new BigDecimal(194));
            try {
                String[] ids = id.split(",");
                for (String idStr : ids) {
                    String[] users = userid.split(",");
                    for (String string : users) {
                        TblStaffMySql user = tblStaffService.findByMySqlId(string);
                        //根据父id查询一级主题菜单
                        TblBiReportMenuMySql menu = this.tblBiReportMenuService.selectMySqlTblBiReportMenu(idStr);
                        //给用户主题表赋值
                        TblBiReportMenuMySql page = new TblBiReportMenuMySql();
                        page.setCreatedate(new Date());
                        page.setCreater(user.getUsername());
                        page.setForbidden(menu.getForbidden());
                        page.setMemo1(menu.getMemo1());
                        page.setMemo2(menu.getMemo2());
                        page.setPagecode(menu.getPagecode());
                        page.setPageDes(menu.getPageDes());
                        page.setPagename(menu.getPagename());
                        page.setPageuser(menu.getPageuser());
                        page.setRqurl(menu.getRqurl());
                        page.setRightid(new BigDecimal(194));
                        page.setTreeid(new BigDecimal(string));
                        page.setUnit(user.getOrgid().toString());
                        page.setType(menu.getType());
                        tblBiReportMenuService.addMySqlPage(page);

                        //根据id查询二级主题菜单
                        List<TblBiReportMenuMySql> findByFatherid = this.tblBiReportMenuService.selectByMySqlFatherid(idStr);

                        for (TblBiReportMenuMySql tblBiReportMenu : findByFatherid) {
                            TblBiReportMenuMySql pagetow = new TblBiReportMenuMySql();
                            pagetow.setCreatedate(new Date());
                            pagetow.setCreater(user.getUsername());
                            pagetow.setForbidden(tblBiReportMenu.getForbidden());
                            pagetow.setMemo1(tblBiReportMenu.getMemo1());
                            pagetow.setMemo2(tblBiReportMenu.getMemo2());
                            pagetow.setPagecode(tblBiReportMenu.getPagecode());
                            pagetow.setPageDes(tblBiReportMenu.getPageDes());
                            pagetow.setPagename(tblBiReportMenu.getPagename());
                            pagetow.setPageuser(tblBiReportMenu.getPageuser());
                            pagetow.setRqurl(tblBiReportMenu.getRqurl());
                            pagetow.setRightid(new BigDecimal(194));
                            pagetow.setTreeid(new BigDecimal(string));
                            pagetow.setUnit(user.getOrgid().toString());
                            pagetow.setPagebody(page.getPageid());
                            tblBiReportMenuService.addMySqlPage(pagetow);
                            if (tblBiReportMenu.getRqurl() == null) {
                                //查询主题图表，添加
                                List<TblBiCkEchartsMySql> chartsPages = tblBiCkEchartsService
                                        .getMySqlChartsPages(tblBiReportMenu.getPageid().toString());
                                for (TblBiCkEchartsMySql charts : chartsPages) {
                                    TblBiChartMySql biChart = new TblBiChartMySql();
                                    biChart.setTitle(charts.getTitle());
                                    biChart.setAxisx(charts.getAxisx());
                                    biChart.setAxisy(charts.getAxisy());
                                    biChart.setChartname(charts.getChartname());
                                    biChart.setCharttype(charts.getCharttype());
                                    biChart.setMemo(charts.getMemo());
                                    biChart.setPointx(charts.getPointx());
                                    biChart.setPointy(charts.getPointy());
                                    biChart.setWidth(charts.getWidth());
                                    biChart.setHeight(charts.getHeight());
                                    biChart.setPageType(charts.getPageType());
                                    //添加图表
                                    tblBiChartService.addMySql(biChart);

                                }
                            }
                        }

                    }
                    resultMap.put("code", "1");

                    JSONObject jsonObjectMav = new JSONObject(resultMap);
                    result = jsonObjectMav.toString();
                    return result;
                }
            } catch (Exception e) {

                e.printStackTrace();

            } finally {
                resultMap.put("code", "1");

                JSONObject jsonObjectMav = new JSONObject(resultMap);
                result = jsonObjectMav.toString();
                return result;
            }
        }
    }

    //风险分类
    @RequestMapping(value = "/selectallrisk", method = {RequestMethod.POST})
    @ApiOperation(value = "根据当前公司获取风险分类数据默认获取一级分类(主题仓库-风险分类-列表查询(编号、一类))")
    public String selectallrisk(HttpServletRequest request,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                @RequestParam(value = "riskLevel", required = false) String riskLevel,
                                @RequestParam(value = "parentId", required = false) String parentId,
                                @RequestParam(value = "riskNumber", required = false) String riskNumber,
                                @RequestParam(value = "riskclass", required = false) String riskclass,
                                @RequestParam(value = "type", required = false) String type) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        if (riskLevel == null) {
            riskLevel = "1";
        }
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        PageInfo<RiskClass> pageInfo = null;
        RiskClass risk = new RiskClass();

        if (!riskLevel.equals("1") && "back".equals(type)) {
            choiceMap = new HashMap<String, Object>(0);
            choiceMap.put("riskid", parentId);
            String tree = HttpClient.request(HttpClient.sxjm_findone, choiceMap, null);
            net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);
            String resultone = jsonObject.getString("result");
            if (resultone != null && resultone.equals("true")) {
                String result1 = jsonObject.getString("entity");

                jsonObject = net.sf.json.JSONObject.fromObject(result1);
                risk = (RiskClass) net.sf.json.JSONObject.toBean(jsonObject, RiskClass.class);
                parentId = risk.getParentid();
            }
        } else if ("back".equals(type)) {
            parentId = "";
        }
        choiceMap = new HashMap<String, Object>(0);
        choiceMap.put("parentid", parentId);
        choiceMap.put("level", riskLevel);
        choiceMap.put("pageNumber", pageNumber);
        choiceMap.put("riskNumber", riskNumber);
        choiceMap.put("riskclass", riskclass);
        choiceMap.put("pagesize", pageSize);
        choiceMap.put("orgid", staff.getCurrentOrg().getOrgid());
        String tree = HttpClient.request(HttpClient.sxjm_bypanrent, choiceMap, null);
        net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);
        String resultone = jsonObject.getString("result");
        if (resultone != null && resultone.equals("true")) {
            String result1 = jsonObject.getString("list");
            String count = jsonObject.getString("count");
            List<RiskClass> list = JSON.parseObject(result1, new TypeReference<List<RiskClass>>() {
            });
            pageInfo = new PageInfo<RiskClass>();
            pageInfo.setCurrentPage(pageNumber);
            //pageInfo.setPageSize(15);
            pageInfo.setPageSize(pageSize);
            pageInfo.setTotalRecord(Integer.parseInt(count));
            pageInfo.setTlist(list);
        }
        choiceMap.put("riskLevel", riskLevel);
        choiceMap.put("parentId", parentId);
        choiceMap.put("pageInfo", pageInfo);
        resultMap.put("data", choiceMap);
        resultMap.put("code", "1");
        resultMap.put("msg", "数据访问成功");
        JSONObject jsonObjectMav = new JSONObject(resultMap);
        result = jsonObjectMav.toString();
        return result;
    }

    @RequestMapping(value = "/toAddRiskClass", method = {RequestMethod.POST})
    @ApiOperation(value = "新增风险分类页面")
    public String toAddRiskClass(HttpServletRequest request,
                                 @RequestParam(value = "riskLevel", required = true) String riskLevel,
                                 @RequestParam(value = "parentId", required = false) String parentId) throws Exception {
        String result1 = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);

        RiskClass risk = null;
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        if (Integer.parseInt(riskLevel) != 1) {
            choiceMap.put("riskid", parentId);
            String tree = HttpClient.request(HttpClient.sxjm_findone, choiceMap, null);
            net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);
            String resultone = jsonObject.getString("result");
            if (resultone != null && resultone.equals("true")) {
                String result = jsonObject.getString("entity");
                risk = JSON.parseObject(result, new TypeReference<RiskClass>() {
                });
            }
        }
        resultMap.put("parentId", parentId);
        resultMap.put("risk", risk);
        resultMap.put("riskLevel", riskLevel);
        JSONObject jsonObjectmav = new JSONObject(resultMap);
        result1 = jsonObjectmav.toString();
        return result1;
    }


    @RequestMapping(value = "/addRiskClass", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "新增与修改风险分类")
    public Integer addRiskClass(HttpServletRequest request, RiskClass riskClass,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        // TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        riskClass.setOrgid(staff.getCurrentOrg().getOrgid().toString());
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        choiceMap.put("risk", JSONObject.toJSON(riskClass));
        String tree = HttpClient.request(HttpClient.sxjm_saverisk, choiceMap, null);
        net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);

        String resultone = jsonObject.getString("result");
        if (resultone != null && resultone.equals("true")) {
            return 0;
        }
        return -1;
    }

    /**
     * 获取风险分类的列表,新增报表使用
     *
     * @return
     */
    @ApiOperation(value = "获取风险分类的列表,新增报表使用")
    @RequestMapping(value = "/ristclass/list")
    public Map<String, Object> ristClassList(HttpServletRequest request, @RequestParam(value = "riskLevel", required = false) String riskLevel,
                                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                             @RequestParam(value = "parentId", required = false) String parentId,
                                             @RequestParam(value = "riskNumber", required = false) String riskNumber,
                                             @RequestParam(value = "riskclass", required = false) String riskclass,
                                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        // ModelAndView mav = new ModelAndView("view/fxgl_riskClassList");
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);

        // TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        choiceMap.put("parentid", parentId);
        choiceMap.put("level", riskLevel);
        choiceMap.put("pageNumber", pageNumber);
        choiceMap.put("riskNumber", riskNumber);
        choiceMap.put("riskclass", riskclass);
        choiceMap.put("pagesize", "15");
        choiceMap.put("orgid", staff.getCurrentOrg().getOrgid());

        String tree = HttpClient.request(HttpClient.sxjm_bypanrent, choiceMap, null);

        PageInfo<RiskClass> pageInfo = null;
        net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);

        String resultone = jsonObject.getString("result");
        if (resultone != null && resultone.equals("true")) {
            pageInfo = new PageInfo<RiskClass>();
            String result1 = jsonObject.getString("list");
            String count = jsonObject.getString("count");
            List<RiskClass> list = JSON.parseObject(result1, new TypeReference<List<RiskClass>>() {
            });
            //pageInfo.setPageSize(15);
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            pageInfo.setTotalRecord(Integer.parseInt(count));
            pageInfo.setTlist(list);
        }
        resultMap.put("strid", request.getParameter("strid"));
        resultMap.put("riskLevel", riskLevel);
        resultMap.put("parentId", parentId);
        resultMap.put("orgname_2", request.getParameter("strname"));
        resultMap.put("pageInfo", pageInfo);
        resultMap.put("code", "1");
        resultMap.put("msg", "访问接口成功");
        resultMap.put("data", pageInfo);
        return resultMap;
    }


    @RequestMapping(value = "/toModifyRiskClass", method = {RequestMethod.POST})
    @ApiOperation(value = "修改风险分类页面")
    public String toModifyRiskClass(HttpServletRequest request,
                                    @RequestParam(value = "risklevel", required = true) String risklevel,
                                    @RequestParam(value = "parentid", required = false) String parentid,
                                    @RequestParam(value = "riskid", required = false) String riskid) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        RiskClass parentrisk = null;
        RiskClass risk = null;
        String tree;
        String resultone;
        net.sf.json.JSONObject jsonObject;
        String result = null;
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        if (Integer.parseInt(risklevel) != 1) {
            choiceMap.put("riskid", parentid);
            tree = HttpClient.request(HttpClient.sxjm_findone, choiceMap, null);
            jsonObject = net.sf.json.JSONObject.fromObject(tree);
            resultone = jsonObject.getString("result");
            if (resultone != null && resultone.equals("true")) {
                result = jsonObject.getString("entity");
                parentrisk = JSON.parseObject(result, new TypeReference<RiskClass>() {
                });
            }
        }

        choiceMap = new HashMap<String, Object>(0);
        choiceMap.put("riskid", riskid);
        tree = HttpClient.request(HttpClient.sxjm_findone, choiceMap, null);
        jsonObject = net.sf.json.JSONObject.fromObject(tree);
        resultone = jsonObject.getString("result");
        if (resultone != null && resultone.equals("true")) {
            result = jsonObject.getString("entity");
            risk = JSON.parseObject(result, new TypeReference<RiskClass>() {
            });
        }
        resultMap.put("risk", risk);
        resultMap.put("parentId", parentid);
        resultMap.put("parentrisk", parentrisk);
        resultMap.put("riskLevel", risklevel);
        JSONObject jsonResultMap = new JSONObject(resultMap);
        result = jsonResultMap.toString();
        return result;
    }

    @RequestMapping(value = "/getChildrenRiskClass", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "判断是否有子集")
    public Integer getChildrenRiskClass(HttpServletRequest request,
                                        @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                        @RequestParam(value = "riskLevel", required = false) String riskLevel,
                                        @RequestParam(value = "parentId", required = false) String parentId) throws Exception {

        Integer num = 0;

        if (riskLevel == null) {
            riskLevel = "1";
        }
        TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        choiceMap.put("parentid", parentId);
        choiceMap.put("level", riskLevel);
        choiceMap.put("pageNumber", pageNumber);
        choiceMap.put("pagesize", pageSize);
        choiceMap.put("orgid", organization.getOrgid().toString());

        String tree = HttpClient.request(HttpClient.sxjm_bypanrent, choiceMap, null);
        net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);

        String resultone = jsonObject.getString("result");
        if (resultone != null && resultone.equals("true")) {
            String count = jsonObject.getString("count");
            num = Integer.parseInt(count);
        }
        return num;
    }


    @RequestMapping(value = "/removeRiskClass", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "删除风险分类")
    public Integer removeRiskClass(HttpServletRequest request,
                                   @RequestParam(value = "riskId", required = false) String riskId) throws Exception {
        HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
        choiceMap.put("riskid", riskId);

        String tree = HttpClient.request(HttpClient.sxjm_deleterisk, choiceMap, null);
        net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(tree);

        String resultone = jsonObject.getString("result");
        return Integer.parseInt(resultone);
    }

    @RequestMapping(value = "/importRiskClassExcel", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "直接使用InputStream file接收参数也可以/导入")
    public Integer importRiskClassExcel(MultipartFile file,
                                        @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        InputStream in = file.getInputStream();
        XSSFWorkbook workbook = new XSSFWorkbook(in);
        try {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            String orgId = staff.getCurrentOrg().getOrgid().toString();
            RiskClass onerisk = null;
            RiskClass tworisk = null;
            RiskClass threerisk = null;
            XSSFCell cell = null;
            XSSFRow row = null;
            String riskNumber = null;
            String oneContent = null;
            String twoContent = null;
            String threeContent = null;
            String oneNumber = null;
            String twoNumber = null;
            String policybasis = null;
            List<RiskClass> oneList = new ArrayList<RiskClass>(0);
            StringBuffer sbNumber = new StringBuffer("(");
            for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
                //获取工作薄中的工作表
                XSSFSheet sheet = workbook.getSheetAt(i);
                //遍历工作表的行,从第3行开始读数据(索引从0开始)
                for (int x = 2; x < sheet.getPhysicalNumberOfRows(); x++) {
                    row = sheet.getRow(x);
                    //如果此工作表有数据
                    if (row != null) {
                        //遍历每行中每列的数据 row.getPhysicalNumberOfCells()
                        //获取单元格
                        cell = row.getCell(0);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            riskNumber = cell.getStringCellValue();

                        }
                        cell = row.getCell(1);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            oneContent = cell.getStringCellValue();
                        }
                        cell = row.getCell(2);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            twoContent = cell.getStringCellValue();

                        }
                        cell = row.getCell(3);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            threeContent = cell.getStringCellValue();

                        }
                        cell = row.getCell(4);
                        if (cell != null) {
                            //获取单元格的值
                            cell.setCellType(1);//字符串
                            policybasis = cell.getStringCellValue();

                        }
                        if (x > 2 && !riskNumber.substring(0, 2).equals(oneNumber)) {
                            oneList.add(onerisk);
                        }
                        if (oneContent != null && oneContent.trim().length() > 0) {
                            onerisk = new RiskClass();
                            oneNumber = riskNumber.substring(0, 2);
                            sbNumber.append("'" + oneNumber + "',");
                            onerisk.setOrgid(orgId);
                            onerisk.setRisklevel("1");
                            onerisk.setRiskNumber(oneNumber);
                            onerisk.setRiskclass(oneContent);
                        }
                        if (twoContent != null && twoContent.trim().length() > 0) {
                            tworisk = new RiskClass();
                            twoNumber = riskNumber.substring(0, 4);
                            sbNumber.append("'" + twoNumber + "',");
                            tworisk.setOrgid(orgId);
                            tworisk.setRisklevel("2");
                            tworisk.setRiskNumber(twoNumber);
                            tworisk.setRiskclass(twoContent);
                            tworisk.setParentid(oneNumber);
                            onerisk.getChildrenList().add(tworisk);
                        }
                        if (threeContent != null && threeContent.trim().length() > 0) {
                            threerisk = new RiskClass();
                            sbNumber.append("'" + riskNumber + "',");
                            threerisk.setOrgid(orgId);
                            threerisk.setRisklevel("3");
                            threerisk.setRiskNumber(riskNumber);
                            threerisk.setRiskclass(threeContent);
                            threerisk.setParentid(twoNumber);
                            threerisk.setPolicybasis(policybasis);
                            tworisk.getChildrenList().add(threerisk);
                        }
                        if (x == (sheet.getPhysicalNumberOfRows() - 1)) {
                            oneList.add(onerisk);
                        }
                    }
                }
            }
            sbNumber.deleteCharAt(sbNumber.length() - 1);
            sbNumber.append(")");
            String number = sbNumber.toString();
            HashMap<String, Object> choiceMap = new HashMap<String, Object>(0);
            System.out.println(JSONObject.toJSON(oneList));
            choiceMap.put("orgId", orgId);
            choiceMap.put("list", JSONObject.toJSON(oneList));
            choiceMap.put("number", number);
            String tree = HttpClient.request(HttpClient.sxjm_exploreexcel, choiceMap, null);
        } finally {
            //读取完毕则关闭流
            in.close();
            workbook.close();
        }
        return 0;
    }

    @RequestMapping(value = "/ywlc/processAnalysis/analysis", method = {RequestMethod.POST})
    public String analysisYwlc(HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<>();
        request.getSession().setAttribute("faflowid", "");
        resultMap.put("msg", "访问成功");
        JSONObject jsonObject = new JSONObject();
        result = jsonObject.toString();
        return result;
    }

//
//    @RequestMapping(value = "/ywlc/processAnalysis/listanalysis")
//    @ApiOperation(value = "查询内部控制流程创建查询的列表页面")
//    public String listanalysisYwlc(HttpServletRequest request,
//                                   @RequestParam(value = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
//                                   @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
//                                   @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token,
//                                   @ApiParam(name="staffId",value="登录用户主键",required=false)String staffId,
//                                   @ApiParam(name = "faid",required = false)String faid,
//                                   @ApiParam(name = "flowid",required = false)BigDecimal flowid) {
//        String result = null;
//        Map<String, Object> resultMap = new HashMap<String, Object>(Integer.parseInt("访问成功"));
//
//        TblFlow flow = new TblFlow();
//        request.getSession().setAttribute("flow", flow);
//        request.getSession().setAttribute("flowid", null);
//        List list = new ArrayList();
//    //    TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
////        TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
//        TblStaff tblStaff = new TblStaff();
//        String flownumber = request.getParameter("flownumber");
//        String flowname = request.getParameter("flowname");
//        String stutes = request.getParameter("sort");
//        String desc = request.getParameter("sort_type");
//
//        String view = request.getParameter("view");
//        String belongsto = request.getParameter("belongsto");
//        if (view == null || view == "") {
//            belongsto = null;
//        }
//
//        // 父流程相关信息
//        TblFlow falow = tblFlowService.findByIdFlows(flowid);
//        if (tblStaff.getTblOrganization().getAudittype() != null && tblStaff.getTblOrganization().getAudittype() == 1) {
//
//            resultMap = tblFlowService.listBySqlPage(staffId, flowid, flowname, flownumber,
//                    stutes, desc,pageNumber, pageSize, belongsto, falow.getFatherflowid(), null,token);
//        } else {
//            List alist = pageBean.getRecordList();
//            for (Object o : pageBean.getRecordList()) {
//                Object[] oa = (Object[]) o;
//                TblFlow flow2 = new TblFlow();
//                flow2.setFlowid(new BigDecimal(oa[0].toString()));
//                flow2.setFlownumber((String) oa[1]);
//                flow2.setFlowname((String) oa[2]);
//                if (oa[3] != null && !oa[3].equals("")) {
//                    TblOrganization organ = tblOrganizaService.findByStringId((String) oa[3]);
//                    if (organ != null) {
//                        flow2.setCompany(organ != null ? organ.getOrgname() : "");
//                        flow2.setComName(organ.getOrgname());
//                    }
//                } else {
//                    flow2.setCompany("");
//                }
//                if (oa[4] != null && !oa[4].equals("")) {
//                    TblOrganization organ = tblOrganizaService.findByStringId((String) oa[4]);
//                    if (organ != null) {
//                        flow2.setDepartincharge(organ != null ? organ.getOrgname() : "");
//                        flow2.setDeparChargeName(organ.getOrgname());
//                    }
//                } else {
//                    flow2.setDepartincharge("");
//                }
//                flow2.setCreatetime((String) oa[5]);
//                flow2.setFlowstatus((String) oa[6]);
//                flow2.setFatherflowid(new BigDecimal(oa[7] == null ? "0" : oa[7].toString()));
//                flow2.setDepartassist(oa[8] == null ? null : oa[8].toString());
//                flow2.setStatus(oa[9] == null ? null : Integer.parseInt(oa[9].toString()));
//                flow2.setFiringStatus(oa[12] == null ? null : Integer.parseInt(oa[12].toString()));
//                list.add(flow2);
//            }
//            JSONObject jsonObjectMAV = new JSONObject(resultMap);
//            result = jsonObjectMAV.toString();
//
//        }
//        return result;
//    }

    /**
     * 业务创建新-新建
     *
     * @param vo
     * @param token
     * @return
     */
    @RequestMapping(value = "/ywlc/processAnalysis/add_proces_save", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建左侧-新建")
    @ResponseBody
    public String add_process_ywlces(TblFlowVo vo, @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {


        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.SaveTblFlow(vo, token);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 业务创建新-修改
     *
     * @param vo
     * @return
     */
    @RequestMapping(value = "/ywlc/processAnalysis/process_update", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建左侧-修改")
    @ResponseBody
    public String process_modify_save_ywlc_pro(TblFlowVo vo) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.UpdateTblFlow(vo);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/ywlc/processAnalysis/process_add", method = {RequestMethod.POST})
    @ApiOperation(value = "系统配置-业务创建-新建")
    public String process_add_ywlc(HttpServletRequest request) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            String currentpid = (String) request.getSession().getAttribute("currentProcess");
            if (currentpid == null) {
                currentpid = "0";
            }
            String ff = request.getParameter("ffid");
            if (ff != null && !"".equals(ff)) {
                currentpid = ff;
                request.getSession().setAttribute("currentProcess", ff);
            }
            String orgid = request.getParameter("orgid");
            TblFlow flow = tblFlowService.findById(currentpid);
            String isFlowdb = request.getParameter("isflowdb");
            resultMap.put("msg", "访问成功");
            if (currentpid != null && !"".equals(currentpid) && !"0".equals(currentpid)) {
                resultMap.put("father", flow.getFlowname());
                resultMap.put("commpay", flow.getCompany());
                resultMap.put("folwIdNo", flow.getFlownumber());
            } else {
                TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
                if (isFlowdb != null && isFlowdb.equals("1") && !"".equals(isFlowdb)) {
                    if (flow.getFlowname().equals("流程创建")) {
                        resultMap.put("father", "行业流程");
                    } else {
                        resultMap.put("father", flow.getFlowname());
                    }
                } else {
                    resultMap.put("father", "流程创建");
                    String orgids = (String) request.getSession().getAttribute("ogridb");
                    if (orgids != null && !"".equals(orgids)) {
                        resultMap.put("commpay", orgids);
                    } else {
                        resultMap.put("commpay", attribute1.getOrgid());
                    }
                }
            }
            resultMap.put("currentpid", currentpid);
            resultMap.put("orgid", orgid);
            resultMap.put("isFlowdb", isFlowdb);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            String currentpid = (String) request.getSession().getAttribute("currentProcess");
            if (currentpid == null) {
                currentpid = "0";
            }
            String ff = request.getParameter("ffid");
            if (ff != null && !"".equals(ff)) {
                currentpid = ff;
                request.getSession().setAttribute("currentProcess", ff);
            }
            String orgid = request.getParameter("orgid");
            TblFlowMySql flow = tblFlowService.findByMySqlId(currentpid);
            String isFlowdb = request.getParameter("isflowdb");
            resultMap.put("msg", "访问成功");
            if (currentpid != null && !"".equals(currentpid) && !"0".equals(currentpid)) {
                resultMap.put("father", flow.getFlowname());
                resultMap.put("commpay", flow.getCompany());
                resultMap.put("folwIdNo", flow.getFlownumber());
            } else {
                TblOrganizationMySql attribute1 = (TblOrganizationMySql) request.getSession().getAttribute("hbOrgEntity");
                if (isFlowdb != null && isFlowdb.equals("1") && !"".equals(isFlowdb)) {
                    if (flow.getFlowname().equals("流程创建")) {
                        resultMap.put("father", "行业流程");
                    } else {
                        resultMap.put("father", flow.getFlowname());
                    }
                } else {
                    resultMap.put("father", "流程创建");
                    String orgids = (String) request.getSession().getAttribute("ogridb");
                    if (orgids != null && !"".equals(orgids)) {
                        resultMap.put("commpay", orgids);
                    } else {
                        resultMap.put("commpay", attribute1.getOrgid());
                    }
                }
            }
            resultMap.put("currentpid", currentpid);
            resultMap.put("orgid", orgid);
            resultMap.put("isFlowdb", isFlowdb);
            JSONObject jsonObjectMV = new JSONObject(resultMap);
            result = jsonObjectMV.toString();
            return result;
        }
    }

    @RequestMapping(value = "/ywlc/processAnalysis/save_add", method = {RequestMethod.POST})
    public @ResponseBody
    String del_process_ywlcs(HttpServletRequest request) {
        String num = request.getParameter("num");
        String str = "";
        TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选则的机构
        List list = tblFlowService.findByis(num.trim(), attribute.getOrgid().toString());
        if (list != null && list.size() > 0) {
            str = "0";
        }
        return str;
    }


    @RequestMapping(value = "/ywlc/processAnalysis/process_modify", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建左侧-修改回显")
    public String process_modify_ywlc(@ApiParam(name = "flowid", value = "flowid", required = true) String flowid,
                                      @ApiParam(name = "isflowdb", value = "isflowdb", required = false) String isflowdb) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (flowid != null) {
                TblFlow flow = tblFlowService.findById(flowid);
                TblFlow father = tblFlowService.findById(flow.getFatherflowid().toString());
                if (isflowdb != null && !"".equals(isflowdb) && isflowdb.equals("1")) {
                    if (father == null) {
                        resultMap.put("flowid", flow.getFlowid());
                        resultMap.put("isflowdb", isflowdb);
                        resultMap.put("father", "行业流程");
                    } else {
                        if (father.getFlowname().equals("流程创建")) {
                            resultMap.put("father", "行业流程");
                            resultMap.put("isflowdb", isflowdb);
                        } else {
                            resultMap.put("father", father.getFlowname());
                            resultMap.put("isflowdb", isflowdb);
                        }
                    }
                } else {
                    if (father == null) {
                        resultMap.put("father", "流程创建");
                        resultMap.put("flowid", 0);
                    } else {
                        resultMap.put("father", father.getFlowname());
                        resultMap.put("flowid", flow.getFlowid());
                    }
                }
                resultMap.put("flownumber", flow.getFlownumber());
                resultMap.put("flowname", flow.getFlowname());
                JSONObject jsonObjectMV = new JSONObject(resultMap);
                result = jsonObjectMV.toString();
                return result;
            }
            return null;
        } else {
            if (flowid != null) {
                TblFlowMySql flow = tblFlowService.findByMySqlId(flowid);
                TblFlowMySql father = tblFlowService.findByMySqlId(flow.getFatherflowid().toString());
                if (isflowdb != null && !"".equals(isflowdb) && isflowdb.equals("1")) {
                    if (father == null) {
                        resultMap.put("flowid", flow.getFlowid());
                        resultMap.put("isflowdb", isflowdb);
                        resultMap.put("father", "行业流程");
                    } else {
                        if (father.getFlowname().equals("流程创建")) {
                            resultMap.put("father", "行业流程");
                            resultMap.put("isflowdb", isflowdb);
                        } else {
                            resultMap.put("father", father.getFlowname());
                            resultMap.put("isflowdb", isflowdb);
                        }
                    }
                } else {
                    if (father == null) {
                        resultMap.put("father", "流程创建");
                        resultMap.put("flowid", 0);
                    } else {
                        resultMap.put("father", father.getFlowname());
                        resultMap.put("flowid", flow.getFlowid());
                    }
                }
                resultMap.put("flownumber", flow.getFlownumber());
                resultMap.put("flowname", flow.getFlowname());
                JSONObject jsonObjectMV = new JSONObject(resultMap);
                result = jsonObjectMV.toString();
                return result;
            }
            return null;
        }
    }


    /**
     * 业务创建-启用/弃用
     *
     * @param request
     * @param flowid
     * @param firing
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/ywlc/changeFiringStatus", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "系统配置-业务创建-启用/弃用。注：三级流程启用 同一个二级流程下只能有一个三级流程启用")
    public Integer ywlc_changeFiringStatus(HttpServletRequest request,
                                           @RequestParam(value = "flowid", required = true) Integer flowid,
                                           @RequestParam(value = "firing", required = true) Integer firing,
                                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        Integer result = 0;
        FileOutputStream fileOutStream = null;
        OutputStream os = null;
        ZipOutputStream zipOut = null;
        FileOutputStream fous = null;
        try {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("orgId", user.getCurrentOrg().getOrgid());
            fields.put("flowId", flowid);
            String resultActiviti = null;
            if (firing == 1) {
                Integer count = this.tblFlowService.findTblFlowStartUpFiringStatus(flowid, firing);
                if (count == 0) {
                    // 流程启用时部署工作流
                    resultActiviti = HttpClient.request(activitiModelerUrl + "/deployActivitiModel", fields, null);
                    JSONObject resultjs = JSONObject.parseObject(resultActiviti);
                    result = Integer.parseInt(resultjs.getString("result"));
                    if (result == 0) {
                        String deployKey = resultjs.getString("deployKey");
                        String modelKey = resultjs.getString("modelKey");
                        byte[] modelData = resultjs.getBytes("moduleData");
                        byte[] picData = resultjs.getBytes("picData");
                        String processName = deployKey + ".bpmn";
                        String imgName = modelKey + "." + deployKey + ".png";
                        //String path = this.getClass().getClassLoader().getResource("/process").getPath();
                        // new一个文件对象用来保存图片，默认保存当前工程根目录
                        File imageFile = new File(filepath + imgName);
                        // 创建输出流
                        fileOutStream = new FileOutputStream(imageFile);
                        // 写入数据
                        fileOutStream.write(picData);

                        /**
                         * 流程文件
                         */
                        File dir = new File(filepath + processName);
                        if (!dir.exists() && dir.isDirectory()) {// 判断文件目录是否存在
                            dir.mkdirs();
                        }
                        os = new FileOutputStream(filepath + processName);
                        os.write(modelData, 0, modelData.length);
                        os.flush();

                        /**
                         * 流程zip文件
                         */
                        // **这个集合就是你想要打包的所有文件*//*
                        List<File> files = new ArrayList<File>();
                        // 压缩的文件url
                        this.getClass().getResourceAsStream(processName);
                        files.add(new File(filepath + processName));
                        files.add(new File(filepath + imgName));
                        String zipName = deployKey + ".zip";
                        String zipUrl = filepath + zipName;
                        File file = new File(zipUrl);
                        if (!file.exists()) {
                            file.createNewFile();
                        }
                        // 创建文件输出流
                        fous = new FileOutputStream(file);
                        zipOut = new ZipOutputStream(new BufferedOutputStream(fous));
                        zipFile(files, zipOut);
                        result = this.tblFlowService.modifyTblFlowFiringStatus(flowid, firing);
                    } else {
                        return result;
                    }
                } else {
                    return -1;
                }
            } else {
                result = this.tblFlowService.modifyTblFlowFiringStatus(flowid, firing);
                resultActiviti = HttpClient.request(activitiModelerUrl + "/deleteActivitiModel", fields, null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fileOutStream != null) {
                fileOutStream.close();
            }
            if (os != null) {
                os.close();
            }
            if (zipOut != null) {
                zipOut.close();
            }
            if (fous != null) {
                fous.close();
            }
        }
        return result;
    }

    @ApiOperation(value = "把接受的全部文件打成压缩包")
    public static void zipFile(List<File> files, ZipOutputStream outputStream) {
        int size = files.size();
        for (int i = 0; i < size; i++) {
            File file = (File) files.get(i);
            zipFile((List<File>) file, outputStream);
        }
    }


    @RequestMapping(value = "/ywlc/processAnalysis/del_process", method = {RequestMethod.POST})
    @ApiOperation(value = "系统配置-业务创建-删除")
    @ResponseBody
    public String del_process_ywlc(@ApiParam(name = "flowid", value = "flowid", required = true) String flowid,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            // 中间表
            TblRiskFlow flowid1 = new TblRiskFlow();
            flowid1.setFlowid(Long.parseLong(flowid.toString()));
            flowid1 = tblFlowService.findBysql(flowid);
            if (flowid1 != null) {
                tblFlowService.deleteTblRiskFlow(flowid);
                // 风险表
                tblRiskService.delRisk(flowid1.getRiskid());
            }
            if (flowid != null) {
                List<TblFlowdes> list = tblFlowdesService.returnFlowBysqls(flowid);
                if (list.size() > 0 && list != null) {
                    for (int i = 0; i < list.size(); i++) {
                        TblFlowdes flowdes = (TblFlowdes) list.get(i);
                        tblFlowdesService.delete(flowdes.getFlowdesid().toString());
                    }
                }
                TblFlow flow = tblFlowService.findById(flowid);
                List<TblFlowBussiness> findByFlowud = tblFlowBussinessService.findByFlowud(flowid, null);
                if (findByFlowud != null && findByFlowud.size() > 0) {
                    tblFlowBussinessService.delete(findByFlowud.get(0));
                }
                List<TblFlow> flownumber = tblFlowService.findByFlownumber(flow.getFlowid().toString());
                for (TblFlow tblFlow : flownumber) {
                    tblFlowService.deleteBy(tblFlow);
                }
                HashMap<String, Object> fields = new HashMap<String, Object>(0);
                fields.put("flowid", flowid);
                fields.put("orgId", user.getCurrentOrg().getOrgid());
                String result = HttpClient.request(formurl + "/form/dropFormInfoAllByFlowId", fields, null);
                JSONObject resultjs = JSONObject.parseObject(result);
                result = HttpClient.request(activitiModelerUrl + "/deleteActivitiAll", fields, null);
                tblFlowService.deleteBy(flow);
            }
            return JsonBean.success();
        } else {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            // 中间表
            TblRiskFlowMySql flowid1 = new TblRiskFlowMySql();
            flowid1.setFlowid(Long.parseLong(flowid.toString()));
            flowid1 = tblFlowService.findByMySql(flowid);
            if (flowid1 != null) {
                tblFlowService.deleteTblRiskFlow(flowid);
                // 风险表
                tblRiskService.delRisk(flowid1.getRiskid());
            }
            if (flowid != null) {
                List<TblFlowdesMySql> list = tblFlowdesService.returnFlowByMySqls(flowid);
                if (list.size() > 0 && list != null) {
                    for (int i = 0; i < list.size(); i++) {
                        TblFlowdesMySql flowdes = (TblFlowdesMySql) list.get(i);
                        tblFlowdesService.delete(flowdes.getFlowdesid().toString());
                    }
                }
                TblFlowMySql flow = tblFlowService.findByMySqlId(flowid);
                List<TblFlowBussinessMySql> findByFlowud = tblFlowBussinessService.findByMySqlFlowud(flowid, null);
                if (findByFlowud != null && findByFlowud.size() > 0) {
                    tblFlowBussinessService.deleteMySql(findByFlowud.get(0));
                }
                List<TblFlowMySql> flownumber = tblFlowService.findByMySqlFlownumber(flow.getFlowid().toString());
                for (TblFlowMySql tblFlow : flownumber) {
                    tblFlowService.deleteByMySql(tblFlow);
                }
                HashMap<String, Object> fields = new HashMap<String, Object>(0);
                fields.put("flowid", flowid);
                fields.put("orgId", user.getCurrentOrg().getOrgid());
                String result = HttpClient.request(formurl + "/form/dropFormInfoAllByFlowId", fields, null);
                JSONObject resultjs = JSONObject.parseObject(result);
                result = HttpClient.request(activitiModelerUrl + "/deleteActivitiAll", fields, null);
                tblFlowService.deleteByMySql(flow);
            }
            return JsonBean.success();
        }
    }


    @RequestMapping(value = "/ywlc/processAnalysis/lcfl", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建-流程分类")
    public String addanalysisYwlc(@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowService.findBylcfl(token);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/nbkz/user/list", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建-控制责任人右")
    public String userListss(@ApiParam(name = "pid", value = "pid", required = false) String pid,
                             @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblStaffService.findAllPageBeanPid(pid, pageNumber, pageSize, token);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    /**
     * 业务创建-保存
     *
     * @param flow
     * @param controlmatrix
     * @param risk
     * @param riskBussiness
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/ywlc/processAnalysis/process_analysis_add_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建-保存")
    @ResponseBody
    public String process_analysis_add_save(TblFlow flow, TblControlmatrix controlmatrix, TblRisk risk, TblFlowBussiness riskBussiness,
                                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            TblFlow newFlow = new TblFlow();
            newFlow.setInflowdb(flow.getInflowdb());
            newFlow.setCompany(user.getCurrentOrg().getOrgid().toString());
            newFlow.setDepartincharge(flow.getDepartincharge());//责任部门
            newFlow.setFlownumber(flow.getFlownumber());//业务编号
            newFlow.setFlowname(flow.getFlowname());//流程名称
            newFlow.setDepartassist(flow.getDepartassist());//相关部门
            newFlow.setFatherflowid(flow.getFatherflowid());
            newFlow.setFlowbysystem("1");
            SimpleDateFormat fo = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            newFlow.setCreatetime(fo.format(date));
            if (flow.getFlowid() != null) {
                newFlow.setVersion(flow.getVersion() + 1);
                newFlow.setFlowid(flow.getFlowid());
                tblFlowService.updateFlow(newFlow);
                tblFlowService.flowElseUpdate(newFlow, risk, controlmatrix, riskBussiness);
            } else {
                newFlow.setVersion(flow.getVersion());
                tblFlowService.insertFlolw(newFlow);
                // 插入其他对象
                String flowElseInsert = tblFlowService.flowElseInsert(newFlow, risk, controlmatrix, riskBussiness);
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            resultMap.put("data", newFlow);
            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
            return result;
        } else {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            TblFlowMySql newFlow = new TblFlowMySql();
            newFlow.setInflowdb(flow.getInflowdb());
            newFlow.setCompany(user.getCurrentOrg().getOrgid().toString());
            newFlow.setDepartincharge(flow.getDepartincharge());//责任部门
            newFlow.setFlownumber(flow.getFlownumber());//业务编号
            newFlow.setFlowname(flow.getFlowname());//流程名称
            newFlow.setDepartassist(flow.getDepartassist());//相关部门
            newFlow.setFatherflowid(flow.getFatherflowid());
            newFlow.setFlowbysystem("1");
            SimpleDateFormat fo = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            newFlow.setCreatetime(fo.format(date));
            if (flow.getFlowid() != null) {
                newFlow.setVersion(flow.getVersion() + 1);
                newFlow.setFlowid(flow.getFlowid());
                TblRiskMySql riskMySql = new TblRiskMySql();
                BeanUtils.copyProperties(risk, riskMySql);
                TblControlmatrixMySql controlmatrixMySql = new TblControlmatrixMySql();
                BeanUtils.copyProperties(controlmatrix, controlmatrixMySql);
                TblFlowBussinessMySql riskBussinessMySql = new TblFlowBussinessMySql();
                BeanUtils.copyProperties(riskBussiness, riskBussinessMySql);
                tblFlowService.updateMySqlFlow(newFlow);
                tblFlowService.flowElseMySqlUpdate(newFlow, riskMySql, controlmatrixMySql, riskBussinessMySql);
            } else {
                newFlow.setVersion(flow.getVersion());
                tblFlowService.insertMySqlFlolw(newFlow);
                TblRiskMySql riskMySql = new TblRiskMySql();
                BeanUtils.copyProperties(risk, riskMySql);
                TblControlmatrixMySql controlmatrixMySql = new TblControlmatrixMySql();
                BeanUtils.copyProperties(controlmatrix, controlmatrixMySql);
                TblFlowBussinessMySql riskBussinessMySql = new TblFlowBussinessMySql();
                BeanUtils.copyProperties(riskBussiness, riskBussinessMySql);
                // 插入其他对象
                String flowElseInsert = tblFlowService.flowElseMySqlInsert(newFlow, riskMySql, controlmatrixMySql, riskBussinessMySql);
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            resultMap.put("data", newFlow);
            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
            return result;
        }
    }

    @RequestMapping(value = "/ywlc/processAnalysis/analysis_list_add_modify", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建-子集修改回显")
    public String analysis_add_modifyYwlc(
            @ApiParam(name = "flowid", value = "flowid", required = true) String flowid,
            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                TblFlow dp = this.tblFlowService.findById(flowid);
                if (dp.getCompany() != null) {
                    TblOrganization organ = tblOrganizaService.findById(dp.getCompany());
                    dp.setComName(organ.getOrgname());
                }
                if (dp.getDepartincharge() != null) {
                    TblOrganization organ = tblOrganizaService.findById(dp.getDepartincharge());
                    dp.setDeparChargeName(organ.getOrgname());
                }
                if (dp.getDepartassist() != null && !dp.getDepartassist().equals("")) {
                    String[] orid = dp.getDepartassist().split(",");
                    String r = "";
                    for (String string : orid) {
                        TblOrganization organ = tblOrganizaService.findById(string);
                        r += organ.getOrgname() + ",";
                    }
                    r = r.substring(0, r.lastIndexOf(","));
                    dp.setDepartissName(r);
                }

                String tcmId = this.tblFlowService.findFlowMatrixByFlowid(dp.getFlowid());
                TblControlmatrix tcl = new TblControlmatrix();
                if (StringUtils.isNotEmpty(tcmId)) {
                    tcl = tblControlmatrixService.getControlmatrix(tcmId);
                }
                List<TblFlow> flows = this.tblFlowService.findByOrgid(user.getCurrentOrg().getOrgid());


                TblFlowBussiness riskBussiness = tblFlowBussinessService.findUniqueByFlowId(dp.getFlowid());
                TblRisk risk = tblRiskService.findTblRiskByFlowId(dp.getFlowid());

                dataMap.put("risk", risk);
                dataMap.put("riskBussiness", riskBussiness);
                dataMap.put("flows", flows);
                dataMap.put("controlMatrix", tcl);
                dataMap.put("dp", dp);
                dataMap.put("activitiModelerUrl", activitiModelerUrl);
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
                JSONObject jsonObject = new JSONObject(resultMap);
                result = jsonObject.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                TblFlowMySql dp = this.tblFlowService.findByMySqlId(flowid);
                if (dp.getCompany() != null) {
                    TblOrganizationMySql organ = tblOrganizaService.findByMySqlId(dp.getCompany());
                    dp.setComName(organ.getOrgname());
                }
                if (dp.getDepartincharge() != null) {
                    TblOrganizationMySql organ = tblOrganizaService.findByMySqlId(dp.getDepartincharge());
                    dp.setDeparChargeName(organ.getOrgname());
                }
                if (dp.getDepartassist() != null && !dp.getDepartassist().equals("")) {
                    String[] orid = dp.getDepartassist().split(",");
                    String r = "";
                    for (String string : orid) {
                        TblOrganizationMySql organ = tblOrganizaService.findByMySqlId(string);
                        r += organ.getOrgname() + ",";
                    }
                    r = r.substring(0, r.lastIndexOf(","));
                    dp.setDepartissName(r);
                }

                String tcmId = this.tblFlowService.findFlowMatrixByFlowid(dp.getFlowid());
                TblControlmatrixMySql tcl = new TblControlmatrixMySql();
                if (StringUtils.isNotEmpty(tcmId)) {
                    tcl = tblControlmatrixService.getMySqlControlmatrix(tcmId);
                }
                List<TblFlowMySql> flows = this.tblFlowService.findByMySqlOrgid(user.getCurrentOrg().getOrgid());


                TblFlowBussinessMySql riskBussiness = tblFlowBussinessService.findUniqueByMySqlFlowId(dp.getFlowid());
                TblRiskMySql risk = tblRiskService.findMySqlTblRiskByFlowId(dp.getFlowid());

                dataMap.put("risk", risk);
                dataMap.put("riskBussiness", riskBussiness);
                dataMap.put("flows", flows);
                dataMap.put("controlMatrix", tcl);
                dataMap.put("dp", dp);
                dataMap.put("activitiModelerUrl", activitiModelerUrl);
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
                JSONObject jsonObject = new JSONObject(resultMap);
                result = jsonObject.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @RequestMapping(value = "/ywlc/processAnalysis/ioanalysis", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "内外规列表")
    public String ioanalysisYwlc(@ApiParam(value = "flowid", required = false) String flowid,
                                 @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                 @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowService.findByOrgidAndFlowidobj(flowid, pageNumber, pageSize);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/common/inner_common", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "内规-新建列表")
    public String inner_commonCommon(@ApiParam(value = "flowid", required = false) String flowid,
                                     @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {

        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowInnerRuleService.findByOrgidAndFlowidobj(flowid, pageNumber, pageSize, token);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/save_flow_inner", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "内规-新建选择")
    public @ResponseBody
    String save_internal_regulations(@ApiParam(value = "flowid", required = true) String flowid,
                                     @ApiParam(value = "innerid", required = true) String[] innerid) {
        //List<TblFlowInnerRule> list = tblFlowInnerRuleService.isIfFlowInner(flowid, innerid);
//        if (list == null || list.size() <= 0) {
//        }
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            for (String i : innerid) {
                TblFlowInnerRule inner = new TblFlowInnerRule();
                inner.setFlowid(Integer.parseInt(flowid));
                inner.setInnrulid(Integer.parseInt(i));
                tblFlowInnerRuleService.saveTblFlowInnerRule(inner);
            }
            return JsonBean.success();
        } else {
            for (String i : innerid) {
                TblFlowInnerRuleMySql inner = new TblFlowInnerRuleMySql();
                inner.setFlowid(Integer.parseInt(flowid));
                inner.setInnrulid(Integer.parseInt(i));
                tblFlowInnerRuleService.saveMySqlTblFlowInnerRule(inner);
            }
            return JsonBean.success();
        }
    }

    @RequestMapping(value = "/delete_flow_inner", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "内规-删除")
    public @ResponseBody
    String delete_internal_regulations(@ApiParam(value = "flowid", required = false) String flowid,
                                       @ApiParam(value = "innerid", required = false) String[] innerid) {
        if (flowid != null && innerid != null) {
            for (String i : innerid) {
                TblFlowInnerRule inner = new TblFlowInnerRule();
                inner.setFlowid(Integer.parseInt(flowid));
                inner.setInnrulid(Integer.parseInt(i));
                tblFlowInnerRuleService.delteTblFlowInnerRule(inner);
            }

        }
        return JsonBean.success();
    }

    @RequestMapping(value = "/common/common_outer", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "外规-新建列表")
    public String common_outer(@ApiParam(value = "flowid", required = false) String flowid,
                               @ApiParam(value = "status", required = false) String status,
                               @ApiParam(value = "name", required = false) String name,
                               @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                               @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {


        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowInnerRuleService.findOutRuleByOrgidAndFlowid(name, status, flowid, pageNumber, pageSize, token);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/save_flow_outer", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "外规-新建选择")
    public @ResponseBody
    String save_internal_outers(@ApiParam(value = "flowid", required = true) String flowid,
                                @ApiParam(value = "outrulid", required = true) String[] outrulid) {
        // List<TblFlowIOuterrule> list = flowIOuterruleService.isIfFlowInner(flowid, outrulid);
//        if (list == null || list.size() <= 0) {
//        }
        for (String i : outrulid) {
            TblFlowIOuterrule outer = new TblFlowIOuterrule();
            outer.setFlowid(Integer.parseInt(flowid));
            outer.setOutrulid(Integer.parseInt(i));
            flowIOuterruleService.saveTblFlowInnerRule(outer);
        }
        return JsonBean.success();
    }

    @RequestMapping(value = "/delete_flow_outer", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "外规-删除")
    public @ResponseBody
    String delete_internal_outer(@ApiParam(value = "flowid", required = false) String flowid,
                                 @ApiParam(value = "outrulid", required = false) String outrulid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (flowid != null && outrulid != null) {
                TblFlowIOuterrule outer = new TblFlowIOuterrule();
                outer.setFlowid(Integer.parseInt(flowid));
                outer.setOutrulid(Integer.parseInt(outrulid));
                flowIOuterruleService.delteTblFlowInnerRule(outer);
            }
            return JsonBean.success();
        } else {
            if (flowid != null && outrulid != null) {
                TblFlowIOuterruleMySql outer = new TblFlowIOuterruleMySql();
                outer.setFlowid(Integer.parseInt(flowid));
                outer.setOutrulid(Integer.parseInt(outrulid));
                flowIOuterruleService.delteMySqlTblFlowInnerRule(outer);
            }
            return JsonBean.success();
        }
    }


    @RequestMapping(value = "/ywlc/processAnalysis/isflow", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "业务创建复制到行业-判断")
    public @ResponseBody
    String isflow(HttpServletRequest request) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String selectedId = request.getParameter("selectedId");
            if (selectedId != null && !"".equals(selectedId)) {
                List<TblFlow> flows = tblFlowService.findByfaflowid(selectedId);
                if (flows != null && flows.size() > 0) {
                    return JsonBean.error("该流程不允许复制");
                }

            }
            return JsonBean.success();
        } else {
            String selectedId = request.getParameter("selectedId");
            if (selectedId != null && !"".equals(selectedId)) {
                List<TblFlowMySql> flows = tblFlowService.findByMySqlfaflowid(selectedId);
                if (flows != null && flows.size() > 0) {
                    return JsonBean.error("该流程不允许复制");
                }

            }
            return JsonBean.success();
        }
    }

    //复制到行业列表
    @RequestMapping(value = "/ywlc/processAnalysis/to_leftanalysishy", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public String to_leftanalysisYwlcHy(HttpServletRequest request,
                                        @ApiParam(name = "orgid", value = "orgid", required = false) String orgid,
                                        @ApiParam(name = "selectedId", value = "selectedId", required = false) String selectedId,
                                        @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                List<TblOrganization> findOrgTree = treeService.findOrgTreeObjByHY(user.getCurrentOrg().getOrgid().toString());
                String findOrgId = null;
                if (orgid != null && !"".equals(orgid)) {
                    findOrgId = orgid;
                } else {
                    TblOrganization org1 = tblOrganizaService.getHYFirst();
                    findOrgId = org1.getOrgid().toString();
                }
                String tree = tblFlowService.flowtreehy(findOrgId);
                if (findOrgId == null) {
                    tree = "";
                }
                String treeName = "";
                if (findOrgId != null) {
                    tblRiskcategoryService.initRiskCategory(findOrgId, TblRiskcategory.HYFXSJK);
                    TblOrganization o = tblOrganizaService.findById(findOrgId);
                    treeName = o.getOrgname();

                }
                dataMap.put("orgTree", findOrgTree);
                dataMap.put("tree", tree);
                dataMap.put("treeName", treeName);
                dataMap.put("targetFrame", "mainFramex");
                dataMap.put("orgid", findOrgId);
                dataMap.put("selectedId", selectedId);
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
                JSONObject jsonObject = new JSONObject(resultMap);
                result = jsonObject.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }

            return result;
        } else {
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                List<TblOrganizationMySql> findOrgTree = treeService.findMySqlOrgTreeObjByHY(user.getCurrentOrg().getOrgid().toString());
                String findOrgId = null;
                if (orgid != null && !"".equals(orgid)) {
                    findOrgId = orgid;
                } else {
                    TblOrganizationMySql org1 = tblOrganizaService.getMySqlHYFirst();
                    findOrgId = org1.getOrgid().toString();
                }
                String tree = tblFlowService.flowtreehy(findOrgId);
                if (findOrgId == null) {
                    tree = "";
                }
                String treeName = "";
                if (findOrgId != null) {
                    tblRiskcategoryService.initRiskCategory(findOrgId, TblRiskcategory.HYFXSJK);
                    TblOrganizationMySql o = tblOrganizaService.findByMySqlId(findOrgId);
                    treeName = o.getOrgname();

                }
                dataMap.put("orgTree", findOrgTree);
                dataMap.put("tree", tree);
                dataMap.put("treeName", treeName);
                dataMap.put("targetFrame", "mainFramex");
                dataMap.put("orgid", findOrgId);
                dataMap.put("selectedId", selectedId);
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
                JSONObject jsonObject = new JSONObject(resultMap);
                result = jsonObject.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }

            return result;
        }
    }


    @PostMapping(value = "/ywlc/processAnalysis/to_ywlcbefore", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "复制到行业选择")
    public @ResponseBody
    String tolcbefore(@ApiParam(name = "selectedId", value = "复制的流程id", required = true) String selectedId,
                      @ApiParam(name = "faflowid", value = "父级流程", required = true) String faflowid,
                      @ApiParam(name = "flownumber", value = "流程编号", required = true) String flownumber,
                      @ApiParam(name = "orgid", value = "行业的ID", required = false) String orgid,
                      @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            if (faflowid != null && !"".equals(faflowid) && selectedId != null && !"".equals(selectedId)) {
                TblFlow faflow = tblFlowService.findById(faflowid);
                TblFlow oldflow = tblFlowService.findById(selectedId);
                TblFlow flow = new TblFlow();
                flow.setFlowbysystem(oldflow.getFlowbysystem());
                flow.setFlowname(oldflow.getFlowname());
                flow.setFlownumber(flownumber);
                flow.setFlowstatus(oldflow.getFlowstatus());
                flow.setFlowrange(oldflow.getFlowrange());
                if (orgid != null && orgid != "") {
                    flow.setCompany(orgid);
                    flow.setInflowdb(1);
                } else {
                    flow.setCompany(faflow.getCompany() == null ? user.getCurrentOrg().getOrgid().toString() : faflow.getCompany());
                }
                flow.setDepartassist(oldflow.getDepartassist());
                // flow对象的时间是String类型
                flow.setCreatetime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
                flow.setAffectdegree(oldflow.getAffectdegree());
                if (oldflow.getDepartincharge() == null || oldflow.getDepartincharge() == "") {
                    flow.setDepartincharge(faflow.getDepartincharge());
                } else {
                    flow.setDepartincharge(oldflow.getDepartincharge());
                }

                flow.setEditor(oldflow.getEditor());
                flow.setVersion(1);
                flow.setFatherflowid(new BigDecimal(faflowid));
                flow.setMemo(oldflow.getMemo());
                flow.setRelatedrules(oldflow.getRelatedrules());
                Set inner = oldflow.getTblInnerrules();// 内规
                Set outer = oldflow.getTblOuterrules();// 外规
                Set risks = oldflow.getTblflowRiskEvents();// 风险信息
                Set tblFlowdeses = oldflow.getTblFlowdeses();// 流程描述

                if (oldflow.getFlowchart() != null && !oldflow.getFlowchart().equals("")) {
                    logger.info("添加流程图");
                    File file = new File(filepath + oldflow.getFlowchart());
                    String url = "/data/flow/" + FxglUtil.getTimeString() + ".xml";

                    File file1 = new File(filepath + url);
                    logger.info("判断流程是否有流程图");
                    if (file.exists()) {
                        fileChannelCopy(file, file1);
                        InputStream input = new FileInputStream(filepath + url);
                        FtpUtil.xmlfile(url.substring(url.lastIndexOf("/") + 1), input);
                        flow.setFlowchart(url);
                    }
                }
                tblFlowService.add(flow);

                // 添加关联信息
                for (Object object : risks) {
                    TblRiskevent risk = (TblRiskevent) object;
                    risk.getTblFlowsRisk().add(flow);
                    tblRiskeventService.saveTblRiskevent(risk);
                }
                Set tblControlmatrixes = oldflow.getTblControlmatrixes();// 控制矩阵
                if (tblControlmatrixes != null && tblControlmatrixes.size() > 0) {
                    for (Object object : tblControlmatrixes) {
                        TblControlmatrix com = (TblControlmatrix) object;
                        com.getTblFlows().add(flow);
                        tblControlmatrixService.updateMatrix(com);
                    }
                }

                for (Object object : tblFlowdeses) {
                    logger.info("添加流程描述");
                    TblFlowdes flowdes = (TblFlowdes) object;
                    flowdes.setTblFlow(flow);
                    tblFlowdesService.add(flowdes);
                }
                List<TblFlowBussiness> list = tblFlowBussinessService.findByFlowud(oldflow.getFlowid().toString(), null);
                for (TblFlowBussiness tblFlowBussiness : list) {
                    TblFlowBussiness buss = new TblFlowBussiness();
                    buss.setBussinessdes(tblFlowBussiness.getBussinessdes());
                    buss.setBussinessname(tblFlowBussiness.getBussinessname());
                    buss.setBussinessnumber(tblFlowBussiness.getBussinessnumber());
                    buss.setFlowid(Long.parseLong(flow.getFlowid().toString()));
                    tblFlowBussinessService.save(buss);
                }
                for (Object object : inner) {
                    TblInnerrule inn = (TblInnerrule) object;
                    TblFlowInnerRule fin = new TblFlowInnerRule();
                    fin.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    fin.setInnrulid(Integer.parseInt(inn.getInnrulid().toString()));
                    tblFlowInnerRuleService.saveTblFlowInnerRule(fin);
                }
                for (Object object : outer) {
                    TblOuterrule out = (TblOuterrule) object;
                    TblFlowIOuterrule ou = new TblFlowIOuterrule();
                    ou.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    ou.setOutrulid(Integer.parseInt(out.getOutrulid().toString()));
                    flow.getTblOuterrules().add(object);
                    flowIOuterruleService.saveTblFlowInnerRule(ou);
                }

                TblRisk risk = tblRiskService.findTblRiskByFlowId(oldflow.getFlowid());
                String sql = "";
                if (risk != null) {
                    TblRisk newrisk = new TblRisk();
                    newrisk.setRisknumber(risk.getRisknumber());
                    newrisk.setRiskname(risk.getRiskname());
                    newrisk.setRiskdes(risk.getRiskdes());
                    newrisk.setRiskprogram(risk.getRiskprogram());
                    this.tblRiskService.saveRisk(newrisk);
                    this.tblFlowService.InsertRiskFLOW(flow.getFlowid(), newrisk.getRiskid());
                }

                HashMap<String, Object> fields = new HashMap<String, Object>(0);
                fields.put("oldFlowId", selectedId);
                fields.put("newFlowId", flow.getFlowid());
                String result = HttpClient.request(formurl + "/form/copyFormInfoToNewFlow", fields, null);
                HashMap<String, Object> activitifields = new HashMap<String, Object>(0);
                activitifields.put("oldRiskid", selectedId);
                activitifields.put("newRiskid", flow.getFlowid());
                result = HttpClient.request(activitiModelerUrl + "/activitiModuleCopy", activitifields, null);
            } else {
                return JsonBean.error("复制失败");
            }
            return JsonBean.success();
        } else {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            if (faflowid != null && !"".equals(faflowid) && selectedId != null && !"".equals(selectedId)) {
                TblFlowMySql faflow = tblFlowService.findByMySqlId(faflowid);
                TblFlowMySql oldflow = tblFlowService.findByMySqlId(selectedId);
                TblFlowMySql flow = new TblFlowMySql();
                flow.setFlowbysystem(oldflow.getFlowbysystem());
                flow.setFlowname(oldflow.getFlowname());
                flow.setFlownumber(flownumber);
                flow.setFlowstatus(oldflow.getFlowstatus());
                flow.setFlowrange(oldflow.getFlowrange());
                if (orgid != null && orgid != "") {
                    flow.setCompany(orgid);
                    flow.setInflowdb(1);
                } else {
                    flow.setCompany(faflow.getCompany() == null ? user.getCurrentOrg().getOrgid().toString() : faflow.getCompany());
                }
                flow.setDepartassist(oldflow.getDepartassist());
                // flow对象的时间是String类型
                flow.setCreatetime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
                flow.setAffectdegree(oldflow.getAffectdegree());
                if (oldflow.getDepartincharge() == null || oldflow.getDepartincharge() == "") {
                    flow.setDepartincharge(faflow.getDepartincharge());
                } else {
                    flow.setDepartincharge(oldflow.getDepartincharge());
                }

                flow.setEditor(oldflow.getEditor());
                flow.setVersion(1);
                flow.setFatherflowid(new BigDecimal(faflowid));
                flow.setMemo(oldflow.getMemo());
                flow.setRelatedrules(oldflow.getRelatedrules());
                Set inner = oldflow.getTblInnerrules();// 内规
                Set outer = oldflow.getTblOuterrules();// 外规
                Set risks = oldflow.getTblflowRiskEvents();// 风险信息
                Set tblFlowdeses = oldflow.getTblFlowdeses();// 流程描述

                if (oldflow.getFlowchart() != null && !oldflow.getFlowchart().equals("")) {
                    logger.info("添加流程图");
                    File file = new File(filepath + oldflow.getFlowchart());
                    String url = "/data/flow/" + FxglUtil.getTimeString() + ".xml";

                    File file1 = new File(filepath + url);
                    logger.info("判断流程是否有流程图");
                    if (file.exists()) {
                        fileChannelCopy(file, file1);
                        InputStream input = new FileInputStream(filepath + url);
                        FtpUtil.xmlfile(url.substring(url.lastIndexOf("/") + 1), input);
                        flow.setFlowchart(url);
                    }
                }
                tblFlowService.addMySql(flow);

                // 添加关联信息
                for (Object object : risks) {
                    TblRiskeventMySql risk = (TblRiskeventMySql) object;
                    risk.getTblFlowsRisk().add(flow);
                    tblRiskeventService.saveMySqlTblRiskevent(risk);
                }
                Set tblControlmatrixes = oldflow.getTblControlmatrixes();// 控制矩阵
                if (tblControlmatrixes != null && tblControlmatrixes.size() > 0) {
                    for (Object object : tblControlmatrixes) {
                        TblControlmatrixMySql com = (TblControlmatrixMySql) object;
                        com.getTblFlows().add(flow);
                        tblControlmatrixService.updateMySqlMatrix(com);
                    }
                }

                for (Object object : tblFlowdeses) {
                    logger.info("添加流程描述");
                    TblFlowdesMySql flowdes = (TblFlowdesMySql) object;
                    flowdes.setTblFlowMySql(flow);
                    tblFlowdesService.addMySql(flowdes);
                }
                List<TblFlowBussinessMySql> list = tblFlowBussinessService.findByMySqlFlowud(oldflow.getFlowid().toString(), null);
                for (TblFlowBussinessMySql tblFlowBussiness : list) {
                    TblFlowBussinessMySql buss = new TblFlowBussinessMySql();
                    buss.setBussinessdes(tblFlowBussiness.getBussinessdes());
                    buss.setBussinessname(tblFlowBussiness.getBussinessname());
                    buss.setBussinessnumber(tblFlowBussiness.getBussinessnumber());
                    buss.setFlowid(Long.parseLong(flow.getFlowid().toString()));
                    tblFlowBussinessService.saveMySql(buss);
                }
                for (Object object : inner) {
                    TblInnerruleMySql inn = (TblInnerruleMySql) object;
                    TblFlowInnerRuleMySql fin = new TblFlowInnerRuleMySql();
                    fin.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    fin.setInnrulid(Integer.parseInt(inn.getInnrulid().toString()));
                    tblFlowInnerRuleService.saveMySqlTblFlowInnerRule(fin);
                }
                for (Object object : outer) {
                    TblOuterruleMySql out = (TblOuterruleMySql) object;
                    TblFlowIOuterruleMySql ou = new TblFlowIOuterruleMySql();
                    ou.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    ou.setOutrulid(Integer.parseInt(out.getOutrulid().toString()));
                    flow.getTblOuterrules().add(object);
                    flowIOuterruleService.saveMySqlTblFlowInnerRule(ou);
                }

                TblRiskMySql risk = tblRiskService.findMySqlTblRiskByFlowId(oldflow.getFlowid());
                String sql = "";
                if (risk != null) {
                    TblRiskMySql newrisk = new TblRiskMySql();
                    newrisk.setRisknumber(risk.getRisknumber());
                    newrisk.setRiskname(risk.getRiskname());
                    newrisk.setRiskdes(risk.getRiskdes());
                    newrisk.setRiskprogram(risk.getRiskprogram());
                    this.tblRiskService.saveMySqlRisk(newrisk);
                    this.tblFlowService.InsertRiskFLOW(flow.getFlowid(), newrisk.getRiskid());
                }

                HashMap<String, Object> fields = new HashMap<String, Object>(0);
                fields.put("oldFlowId", selectedId);
                fields.put("newFlowId", flow.getFlowid());
                String result = HttpClient.request(formurl + "/form/copyFormInfoToNewFlow", fields, null);
                HashMap<String, Object> activitifields = new HashMap<String, Object>(0);
                activitifields.put("oldRiskid", selectedId);
                activitifields.put("newRiskid", flow.getFlowid());
                result = HttpClient.request(activitiModelerUrl + "/activitiModuleCopy", activitifields, null);
            } else {
                return JsonBean.error("复制失败");
            }
            return JsonBean.success();
        }
    }

    /**
     * 从行业复制 列表右
     *
     * @param vo
     * @param token
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/ywlc/processAnalysis/listanalysishy_copy", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "从行业复制")
    public String listanalysishy_copy(CopyVo vo,
                                      @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {
        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowService.finsByPageInfo(vo, token);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @PostMapping(value = "/ywlc/processAnalysis/to_ywlc_copybefore", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "从行业复制选择")
    public @ResponseBody
    String to_ywlc_copybefore(@ApiParam(name = "flowid", value = "复制的流程id", required = true) String flowid,
                              @ApiParam(name = "faflowid", value = "父级流程", required = true) String faflowid,
                              @ApiParam(name = "flownumber", value = "流程编号", required = true) String flownumber,
                              @ApiParam(name = "orgid", value = "行业的ID", required = false) String orgid,
                              @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {

        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (faflowid != null && !"".equals(faflowid) && flowid != null && !"".equals(flowid)) {
                TblFlow faflow = tblFlowService.findById(faflowid);
                TblFlow oldflow = tblFlowService.findById(flowid);
                TblFlow flow = new TblFlow();
                flow.setFlowbysystem(oldflow.getFlowbysystem());
                flow.setFlowname(oldflow.getFlowname());
                flow.setFlownumber(oldflow.getFlownumber());
                flow.setFlowstatus(oldflow.getFlowstatus());
                flow.setFlowrange(oldflow.getFlowrange());
                flow.setCompany(faflow.getCompany());
                flow.setDepartassist(oldflow.getDepartassist());
                flow.setAffectdegree(oldflow.getAffectdegree());
                if (oldflow.getDepartincharge() == null || oldflow.getDepartincharge() == "") {
                    flow.setDepartincharge(faflow.getDepartincharge());
                } else {
                    flow.setDepartincharge(oldflow.getDepartincharge());
                }
                flow.setInflowdb(faflow.getInflowdb());
                flow.setEditor(oldflow.getEditor());
                flow.setVersion(1);
                flow.setFatherflowid(new BigDecimal(faflowid));
                flow.setMemo(oldflow.getMemo());
                flow.setRelatedrules(oldflow.getRelatedrules());
                Set inner = oldflow.getTblInnerrules();// 内规
                Set outer = oldflow.getTblOuterrules();// 外规
                Set risks = oldflow.getTblflowRiskEvents();// 风险信息
                Set tblFlowdeses = oldflow.getTblFlowdeses();// 流程描述

                if (oldflow.getFlowchart() != null && !oldflow.getFlowchart().equals("")) {
                    logger.info("添加流程图");
                    File file = new File(filepath + oldflow.getFlowchart());
                    String url = "/data/flow/" + FxglUtil.getTimeString() + ".xml";

                    File file1 = new File(filepath + url);
                    logger.info("判断流程是否有流程图");
                    if (file.exists()) {
                        fileChannelCopy(file, file1);
                        InputStream input = new FileInputStream(filepath + url);
                        FtpUtil.xmlfile(url.substring(url.lastIndexOf("/") + 1), input);
                        flow.setFlowchart(url);
                    }
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                flow.setCreatetime(sdf.format(new Date()));
                tblFlowService.add(flow);
                for (Object object : risks) {
                    TblRiskevent risk = (TblRiskevent) object;
                    risk.getTblFlowsRisk().add(flow);
                    tblRiskeventService.saveTblRiskevent(risk);
                }
                Set tblControlmatrixes = oldflow.getTblControlmatrixes();// 控制矩阵
                if (tblControlmatrixes != null && tblControlmatrixes.size() > 0) {
                    for (Object object : tblControlmatrixes) {
                        TblControlmatrix com = (TblControlmatrix) object;
                        com.getTblFlows().add(flow);
                        tblControlmatrixService.updateMatrix(com);
                    }
                }
                for (Object object : tblFlowdeses) {
                    logger.info("添加流程描述");
                    TblFlowdes flowdes = (TblFlowdes) object;
                    flowdes.setTblFlow(flow);
                    tblFlowdesService.add(flowdes);
                }
                List<TblFlowBussiness> list = tblFlowBussinessService.findByFlowud(oldflow.getFlowid().toString(), null);
                for (TblFlowBussiness tblFlowBussiness : list) {
                    TblFlowBussiness buss = new TblFlowBussiness();
                    buss.setBussinessdes(tblFlowBussiness.getBussinessdes());
                    buss.setBussinessname(tblFlowBussiness.getBussinessname());
                    buss.setBussinessnumber(tblFlowBussiness.getBussinessnumber());
                    buss.setFlowid(Long.parseLong(flow.getFlowid().toString()));
                    tblFlowBussinessService.save(buss);
                }
                for (Object object : inner) {
                    TblInnerrule inn = (TblInnerrule) object;
                    TblFlowInnerRule fin = new TblFlowInnerRule();
                    fin.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    fin.setInnrulid(Integer.parseInt(inn.getInnrulid().toString()));
                    tblFlowInnerRuleService.saveTblFlowInnerRule(fin);
                }
                for (Object object : outer) {
                    TblOuterrule out = (TblOuterrule) object;
                    TblFlowIOuterrule ou = new TblFlowIOuterrule();
                    ou.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    ou.setOutrulid(Integer.parseInt(out.getOutrulid().toString()));
                    flow.getTblOuterrules().add(object);
                    flowIOuterruleService.saveTblFlowInnerRule(ou);
                }

                TblRisk risk = tblRiskService.findTblRiskByFlowId(oldflow.getFlowid());
                String sql = "";
                if (risk != null) {
                    TblRisk newrisk = new TblRisk();
                    newrisk.setRisknumber(risk.getRisknumber());
                    newrisk.setRiskname(risk.getRiskname());
                    newrisk.setRiskdes(risk.getRiskdes());
                    newrisk.setRiskprogram(risk.getRiskprogram());
                    this.tblRiskService.saveRisk(newrisk);
                    this.tblFlowService.InsertRiskFLOW(flow.getFlowid(), newrisk.getRiskid());
                }
                HashMap<String, Object> fields = new HashMap<String, Object>(0);
                fields.put("oldFlowId", flowid);
                fields.put("newFlowId", flow.getFlowid());
                String result = HttpClient.request(formurl + "/form/copyFormInfoToNewFlow", fields, null);
                HashMap<String, Object> activitifields = new HashMap<String, Object>(0);
                activitifields.put("oldRiskid", flowid);
                activitifields.put("newRiskid", flow.getFlowid());
                result = HttpClient.request(activitiModelerUrl + "/activitiModuleCopy", activitifields, null);
            } else {
                return JsonBean.error("复制失败");
            }
            return JsonBean.success();
        } else {
            if (faflowid != null && !"".equals(faflowid) && flowid != null && !"".equals(flowid)) {
                TblFlowMySql faflow = tblFlowService.findByMySqlId(faflowid);
                TblFlowMySql oldflow = tblFlowService.findByMySqlId(flowid);
                TblFlowMySql flow = new TblFlowMySql();
                flow.setFlowbysystem(oldflow.getFlowbysystem());
                flow.setFlowname(oldflow.getFlowname());
                flow.setFlownumber(oldflow.getFlownumber());
                flow.setFlowstatus(oldflow.getFlowstatus());
                flow.setFlowrange(oldflow.getFlowrange());
                flow.setCompany(faflow.getCompany());
                flow.setDepartassist(oldflow.getDepartassist());
                flow.setAffectdegree(oldflow.getAffectdegree());
                if (oldflow.getDepartincharge() == null || oldflow.getDepartincharge() == "") {
                    flow.setDepartincharge(faflow.getDepartincharge());
                } else {
                    flow.setDepartincharge(oldflow.getDepartincharge());
                }
                flow.setInflowdb(faflow.getInflowdb());
                flow.setEditor(oldflow.getEditor());
                flow.setVersion(1);
                flow.setFatherflowid(new BigDecimal(faflowid));
                flow.setMemo(oldflow.getMemo());
                flow.setRelatedrules(oldflow.getRelatedrules());
                Set inner = oldflow.getTblInnerrules();// 内规
                Set outer = oldflow.getTblOuterrules();// 外规
                Set risks = oldflow.getTblflowRiskEvents();// 风险信息
                Set tblFlowdeses = oldflow.getTblFlowdeses();// 流程描述

                if (oldflow.getFlowchart() != null && !oldflow.getFlowchart().equals("")) {
                    logger.info("添加流程图");
                    File file = new File(filepath + oldflow.getFlowchart());
                    String url = "/data/flow/" + FxglUtil.getTimeString() + ".xml";

                    File file1 = new File(filepath + url);
                    logger.info("判断流程是否有流程图");
                    if (file.exists()) {
                        fileChannelCopy(file, file1);
                        InputStream input = new FileInputStream(filepath + url);
                        FtpUtil.xmlfile(url.substring(url.lastIndexOf("/") + 1), input);
                        flow.setFlowchart(url);
                    }
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                flow.setCreatetime(sdf.format(new Date()));
                tblFlowService.addMySql(flow);
                for (Object object : risks) {
                    TblRiskeventMySql risk = (TblRiskeventMySql) object;
                    risk.getTblFlowsRisk().add(flow);
                    tblRiskeventService.saveMySqlTblRiskevent(risk);
                }
                Set tblControlmatrixes = oldflow.getTblControlmatrixes();// 控制矩阵
                if (tblControlmatrixes != null && tblControlmatrixes.size() > 0) {
                    for (Object object : tblControlmatrixes) {
                        TblControlmatrixMySql com = (TblControlmatrixMySql) object;
                        com.getTblFlows().add(flow);
                        tblControlmatrixService.updateMySqlMatrix(com);
                    }
                }
                for (Object object : tblFlowdeses) {
                    logger.info("添加流程描述");
                    TblFlowdesMySql flowdes = (TblFlowdesMySql) object;
                    flowdes.setTblFlowMySql(flow);
                    tblFlowdesService.addMySql(flowdes);
                }
                List<TblFlowBussinessMySql> list = tblFlowBussinessService.findByMySqlFlowud(oldflow.getFlowid().toString(), null);
                for (TblFlowBussinessMySql tblFlowBussiness : list) {
                    TblFlowBussinessMySql buss = new TblFlowBussinessMySql();
                    buss.setBussinessdes(tblFlowBussiness.getBussinessdes());
                    buss.setBussinessname(tblFlowBussiness.getBussinessname());
                    buss.setBussinessnumber(tblFlowBussiness.getBussinessnumber());
                    buss.setFlowid(Long.parseLong(flow.getFlowid().toString()));
                    tblFlowBussinessService.saveMySql(buss);
                }
                for (Object object : inner) {
                    TblInnerruleMySql inn = (TblInnerruleMySql) object;
                    TblFlowInnerRuleMySql fin = new TblFlowInnerRuleMySql();
                    fin.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    fin.setInnrulid(Integer.parseInt(inn.getInnrulid().toString()));
                    tblFlowInnerRuleService.saveMySqlTblFlowInnerRule(fin);
                }
                for (Object object : outer) {
                    TblOuterruleMySql out = (TblOuterruleMySql) object;
                    TblFlowIOuterruleMySql ou = new TblFlowIOuterruleMySql();
                    ou.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
                    ou.setOutrulid(Integer.parseInt(out.getOutrulid().toString()));
                    flow.getTblOuterrules().add(object);
                    flowIOuterruleService.saveMySqlTblFlowInnerRule(ou);
                }

                TblRiskMySql risk = tblRiskService.findMySqlTblRiskByFlowId(oldflow.getFlowid());
                String sql = "";
                if (risk != null) {
                    TblRiskMySql newrisk = new TblRiskMySql();
                    newrisk.setRisknumber(risk.getRisknumber());
                    newrisk.setRiskname(risk.getRiskname());
                    newrisk.setRiskdes(risk.getRiskdes());
                    newrisk.setRiskprogram(risk.getRiskprogram());
                    this.tblRiskService.saveMySqlRisk(newrisk);
                    this.tblFlowService.InsertRiskFLOW(flow.getFlowid(), newrisk.getRiskid());
                }
                HashMap<String, Object> fields = new HashMap<String, Object>(0);
                fields.put("oldFlowId", flowid);
                fields.put("newFlowId", flow.getFlowid());
                String result = HttpClient.request(formurl + "/form/copyFormInfoToNewFlow", fields, null);
                HashMap<String, Object> activitifields = new HashMap<String, Object>(0);
                activitifields.put("oldRiskid", flowid);
                activitifields.put("newRiskid", flow.getFlowid());
                result = HttpClient.request(activitiModelerUrl + "/activitiModuleCopy", activitifields, null);
            } else {
                return JsonBean.error("复制失败");
            }
            return JsonBean.success();
        }
    }

    //xin
    @RequestMapping(value = "/NewfindOrganizationByTreeAll", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
    @ApiOperation(value = "查询组织架构返回tree列表")
    public @ResponseBody
    String findOrganizationByTree(BigDecimal nodeId, String type) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (null == nodeId) {
                TblOrganization org = tblOrganizaService.getHY();
                nodeId = org.getOrgid();
            }
            String json = "";
            if (StringUtils.isNotBlank(type)) {
                List<Tree> list = this.tblOrganizaService.getTreeHy(nodeId);
                json = JSONObject.toJSONString(list);
            } else {
                List<Tree> list = this.tblOrganizaService.getNodeAllHy(nodeId);
                json = JSONObject.toJSONString(list);
            }
            return json;
        } else {
            if (null == nodeId) {
                TblOrganizationMySql org = tblOrganizaService.getMySqlHY();
                nodeId = org.getOrgid();
            }
            String json = "";
            if (StringUtils.isNotBlank(type)) {
                List<Tree> list = this.tblOrganizaService.getTreeHy(nodeId);
                json = JSONObject.toJSONString(list);
            } else {
                List<Tree> list = this.tblOrganizaService.getNodeAllHy(nodeId);
                json = JSONObject.toJSONString(list);
            }
            return json;
        }
    }


    @RequestMapping(value = "/ywlc/processAnalysis/isflow_del", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "验证行业流程是否是三级流程")
    public @ResponseBody
    String isflow_del(HttpServletRequest request) {
        String selectedId = request.getParameter("selectedId");
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (selectedId != null && !"".equals(selectedId)) {
                TblFlow flow = tblFlowService.findById(selectedId);
                List<TblFlow> flows = tblFlowService.findByfaflowid(selectedId);
                if (flows != null && flows.size() > 0) {
                    return JsonBean.error("请先删除子级");
                }
            }
            return JsonBean.success();
        } else {
            if (selectedId != null && !"".equals(selectedId)) {
                TblFlowMySql flow = tblFlowService.findByMySqlId(selectedId);
                List<TblFlowMySql> flows = tblFlowService.findByMySqlfaflowid(selectedId);
                if (flows != null && flows.size() > 0) {
                    return JsonBean.error("请先删除子级");
                }
            }
            return JsonBean.success();
        }
    }

    @RequestMapping(value = "/ywlc/processAnalysis/analysishy_index", method = {RequestMethod.POST})
    public String analysishy_index(HttpServletRequest request) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<>();
        String faflowid = request.getParameter("faflowid");
        resultMap.put("msg", "访问成功");
        resultMap.put("faflowid", faflowid);
        String moduletype = request.getParameter("moduletype");
        resultMap.put("moduletype", moduletype);
        // 为页面查找区域显隐藏赋值
        String choiceSearch = request.getParameter("choiceSearch");
        if (choiceSearch == null || "".equals(choiceSearch)) {
            choiceSearch = "hide";
        }
        resultMap.put("choiceSearch", choiceSearch);
        JSONObject jsonObjectMV = new JSONObject(resultMap);
        result = jsonObjectMV.toString();
        return result;
    }

    public void fileChannelCopy(File s, File t) {
        FileInputStream fi = null;
        FileOutputStream fo = null;
        FileChannel in = null;
        FileChannel out = null;
        try {
            fi = new FileInputStream(s);
            fo = new FileOutputStream(t);
            in = fi.getChannel();// 得到对应的文件通道
            out = fo.getChannel();// 得到对应的文件通道
            in.transferTo(0, in.size(), out);// 连接两个通道，并且从in通道读取，然后写入out通道
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fi.close();
                in.close();
                fo.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //
//    @RequestMapping(value = "/ywlc/processAnalysis/to_ywlc_copybefore", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
//    public @ResponseBody String to_ywlc_copybefore(HttpServletRequest request) throws Exception {
//        String flowid = request.getParameter("flowid");
//        logger.info("复制的流程id：" + flowid);
//        String faflowid = request.getParameter("faflowid");
//        logger.info("父级流程：" + faflowid);
//        if (faflowid != null && !"".equals(faflowid) && flowid != null && !"".equals(flowid)) {
//            TblFlow faflow = tblFlowService.findById(faflowid);
//
//            TblFlow oldflow = tblFlowService.findById(flowid);
//            TblFlow flow = new TblFlow();
//            flow.setFlowbysystem(oldflow.getFlowbysystem());
//            flow.setFlowname(oldflow.getFlowname());
//            flow.setFlownumber(oldflow.getFlownumber());
//            flow.setFlowstatus(oldflow.getFlowstatus());
//            flow.setFlowrange(oldflow.getFlowrange());
//            flow.setCompany(faflow.getCompany());
//            flow.setDepartassist(oldflow.getDepartassist());
//            flow.setAffectdegree(oldflow.getAffectdegree());
//            if (oldflow.getDepartincharge() == null || oldflow.getDepartincharge() == "") {
//                flow.setDepartincharge(faflow.getDepartincharge());
//            } else {
//                flow.setDepartincharge(oldflow.getDepartincharge());
//            }
//            flow.setInflowdb(faflow.getInflowdb());
//            flow.setEditor(oldflow.getEditor());
//            flow.setVersion(1);
//            flow.setFatherflowid(new BigDecimal(faflowid));
//            flow.setMemo(oldflow.getMemo());
//            flow.setRelatedrules(oldflow.getRelatedrules());
//            Set inner = oldflow.getTblInnerrules();// 内规
//            Set outer = oldflow.getTblOuterrules();// 外规
//            Set risks = oldflow.getTblflowRiskEvents();// 风险信息
//            Set tblFlowdeses = oldflow.getTblFlowdeses();// 流程描述
//
//            if (oldflow.getFlowchart() != null && !oldflow.getFlowchart().equals("")) {
//                logger.info("添加流程图");
//                String path = request.getSession().getServletContext().getRealPath("/WEB-INF/");
//                File file = new File(path + oldflow.getFlowchart());
//                String url = "/data/flow/" + FxglUtil.getTimeString() + ".xml";
//
//                File file1 = new File(path + url);
//                logger.info("判断流程是否有流程图");
//                if (file.exists()) {
//                    fileChannelCopy(file, file1);
//                    InputStream input = new FileInputStream(path + url);
//                    FtpUtil.xmlfile(url.substring(url.lastIndexOf("/") + 1), input);
//                    flow.setFlowchart(url);
//                }
//            }
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            flow.setCreatetime(sdf.format(new Date()));
//            tblFlowService.add(flow);
//            TblRiskeventService servicer = (TblRiskeventService) SpringContextHolder.getBean("TblRiskeventService");
//            for (Object object : risks) {
//                TblRiskevent risk = (TblRiskevent) object;
//                risk.getTblFlowsRisk().add(flow);
//                tblRiskeventService.saveTblRiskevent(risk);
//            }
//            Set tblControlmatrixes = oldflow.getTblControlmatrixes();// 控制矩阵
//            if (tblControlmatrixes != null && tblControlmatrixes.size() > 0) {
//                for (Object object : tblControlmatrixes) {
//                    TblControlmatrix com = (TblControlmatrix) object;
//                    //com.getTblFlows().add(flow);
//                    TblControlmatrixService test = SpringContextHolder.getBean("TblControlMatrixService");
//                    test.modify(com);
//                }
//            }
//            for (Object object : tblFlowdeses) {
//                logger.info("添加流程描述");
//                TblFlowdes flowdes = (TblFlowdes) object;
//                flowdes.setTblFlow(flow);
//                tblFlowdesService.add(flowdes);
//            }
//            List<TblFlowBussiness> list = tblFlowBussinessService.findByFlowud(oldflow.getFlowid().toString(), null);
//            for (TblFlowBussiness tblFlowBussiness : list) {
//                TblFlowBussiness buss = new TblFlowBussiness();
//                buss.setBussinessdes(tblFlowBussiness.getBussinessdes());
//                buss.setBussinessname(tblFlowBussiness.getBussinessname());
//                buss.setBussinessnumber(tblFlowBussiness.getBussinessnumber());
//                buss.setFlowid(Long.parseLong(flow.getFlowid().toString()));
//                tblFlowBussinessService.save(buss);
//            }
//            for (Object object : inner) {
//                TblInnerrule inn = (TblInnerrule) object;
//                TblFlowInnerRule fin = new TblFlowInnerRule();
//                fin.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
//                fin.setInnrulid(Integer.parseInt(inn.getInnrulid().toString()));
//                tblFlowInnerRuleService.saveTblFlowInnerRule(fin);
//            }
//            for (Object object : outer) {
//                TblOuterrule out = (TblOuterrule) object;
//                TblFlowIOuterrule ou = new TblFlowIOuterrule();
//                ou.setFlowid(Integer.parseInt(flow.getFlowid().toString()));
//                ou.setOutrulid(Integer.parseInt(out.getOutrulid().toString()));
//                flow.getTblOuterrules().add(object);
//                flowIOuterruleService.saveTblFlowInnerRule(ou);
//            }
//
//            TblRisk risk = tblRiskService.findTblRiskByFlowId(oldflow.getFlowid());
//            String sql = "";
//            if (risk != null) {
//                TblRisk newrisk = new TblRisk();
//                newrisk.setRisknumber(risk.getRisknumber());
//                newrisk.setRiskname(risk.getRiskname());
//                newrisk.setRiskdes(risk.getRiskdes());
//                newrisk.setRiskprogram(risk.getRiskprogram());
//                this.tblRiskService.saveRisk(newrisk);
//                TblFlow tblFlows = new TblFlow();
//                tblFlows.setFlowid(tblFlows.getFlowid());
//                tblFlows.setRiskid(newrisk.getRiskid());
//                this.tblFlowService.excuteSql(tblFlows);
//            }
//            HashMap<String, Object> fields = new HashMap<String, Object>(0);
//            fields.put("oldFlowId", flowid);
//            fields.put("newFlowId", flow.getFlowid());
//            String result = HttpClient.request(formurl + "/form/copyFormInfoToNewFlow", fields, null);
//            HashMap<String, Object> activitifields = new HashMap<String, Object>(0);
//            activitifields.put("oldRiskid", flowid);
//            activitifields.put("newRiskid", flow.getFlowid());
//            result = HttpClient.request(activitiModelerUrl + "/activitiModuleCopy", activitifields, null);
//        } else {
//            return JsonBean.error("复制失败");
//        }
//        return JsonBean.success();
//    }


//    @RequestMapping(value = "/from/processAnalysis/listanalysis")
//    public String listanalysisYwlc(HttpServletRequest request,
//                                   @RequestParam(value = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
//                                   @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
//                                   @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token,
//                                   @ApiParam(name = "pid",required = false)String pid,
//                                   @ApiParam(name = "flowid",required = false)BigDecimal flowid,
//                                   @ApiParam(name = "belongsto",required = false)String belongsto) {
//        String result = null;
//        Map<String,Object> resultMap = new HashMap<String, Object>(0);
//
//        TblFlow flow = new TblFlow();
//        request.getSession().setAttribute("flow", flow);
//        request.getSession().setAttribute("flowid", null);
//        List<TblFlow> list = new ArrayList<TblFlow>();
//       // TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
//        String flownumber = request.getParameter("flownumber");
//        String flowname = request.getParameter("flowname");
//        String stutes = request.getParameter("sort");
//        String desc = request.getParameter("sort_type");
//
//        resultMap = tblFlowService.listBySqlPage(pid, flowid, flowname, flownumber, stutes, desc,
//                pageNumber,pageSize,belongsto,null,null,token);
//        for (Object o : pageBean.getRecordList()) {
//            Object[] oa = (Object[]) o;
//            TblFlow flow2 = new TblFlow();
//            flow2.setFlowid(new BigDecimal(oa[0].toString()));
//            flow2.setFlownumber((String) oa[1]);
//            flow2.setFlowname((String) oa[2]);
//            if (oa[3] != null && !oa[3].equals("")) {
//                TblOrganization organ = tblOrganizaService.findByStringId((String) oa[3]);
//                if (organ != null) {
//                    flow2.setCompany(organ != null ? organ.getOrgname() : "");
//                    flow2.setComName(organ.getOrgname());
//                }
//            } else {
//                flow2.setCompany("");
//            }
//            if (oa[4] != null && !oa[4].equals("")) {
//                TblOrganization organ = tblOrganizaService.findByStringId((String) oa[4]);
//                if (organ != null) {
//                    flow2.setDepartincharge(organ != null ? organ.getOrgname() : "");
//                    flow2.setDeparChargeName(organ.getOrgname());
//                }
//            } else {
//                flow2.setDepartincharge("");
//            }
//            flow2.setCreatetime((String) oa[5]);
//            flow2.setFlowstatus((String) oa[6]);
//            flow2.setFatherflowid(new BigDecimal(oa[7] == null ? "0" : oa[7].toString()));
//            flow2.setDepartassist(oa[8] == null ? null : oa[8].toString());
//            flow2.setStatus(oa[9] == null ? null : Integer.parseInt(oa[9].toString()));
//            flow2.setSettingid(oa[11]==null?"":oa[11].toString());
//            list.add(flow2);
//        }
//        JSONObject jsonObjectMAV = new JSONObject(resultMap);
//        result = jsonObjectMAV.toString();
//        return result;
//    }


    @RequestMapping(value = "/process/setting", method = {RequestMethod.POST})
    @ApiOperation(value = "流程定义列表")
    public String processSetting(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                 @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        String result = null;
        Map<String, Object> resultMap = this.processSettingService.findByLi(pageNumber, pageSize, token);
        JSONObject jsonObjectVIEW = new JSONObject(resultMap);
        result = jsonObjectVIEW.toString();
        return result;
    }


    @RequestMapping(value = "/findOrganizationByTreeNbkz", method = {RequestMethod.POST})
    @ApiOperation(value = "流程定义-新建选择按钮")
    public String findOrganizationByTreeNukz(HttpServletRequest request, HttpServletResponse response, HttpSession session,
                                             @ApiParam(name = "orgid", value = "orgid", required = false) String orgid,
                                             @ApiParam(name = "str", value = "str", required = false) String str,
                                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        boolean is = false;
        if (StringUtils.isNotBlank(str) && str.equals("3") && StringUtils.isNotBlank(GROUP_STRUCTURE)) {
            is = true;
        }
        String orgtree = "";
        HashMap<String, Object> fields = new HashMap<String, Object>();
        fields.put("nodeId", staff.getCurrentOrg().getOrgid().toString());
        if (is) {
            try {
                orgtree = HttpClient.request(HttpClient.getDeptString, fields, null);
                if (!StringUtils.isNotBlank(orgtree)) {
                    orgtree = tblOrganizaService.findOrgByAllJT(staff.getCurrentOrg().getOrgid().toString());
                }
            } catch (Exception e) {
                orgtree = tblOrganizaService.findOrgByAllJT(staff.getCurrentOrg().getOrgid().toString());
            }
        } else {
            try {
                orgtree = HttpClient.request(HttpClient.getDeptString, fields, null);
                if (!StringUtils.isNotBlank(orgtree)) {
                    orgtree = tblOrganizaService.findOrgByAll(staff.getCurrentOrg().getOrgid().toString());
                }
            } catch (Exception e) {
                orgtree = tblOrganizaService.findOrgByAll(staff.getCurrentOrg().getOrgid().toString());
            }
        }
        return orgtree;
//        PrintWriter out = null;
//        try {
//            response.setCharacterEncoding("UTF-8");
//            out = response.getWriter();
//            out.write("[" + orgtree + "]");
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            out.flush();
//            out.close();
//        }
    }


    @RequestMapping(value = "/processSave", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "流程定义-保存")
    public @ResponseBody
    String cateSave(ProcessSetting setting, HttpServletRequest request,
                    @ApiParam(name = "orgid", value = "orgid", required = false) String orgid,
                    @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                    @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (null != setting.getSettingId()) {
                ProcessSetting processSetting = processSettingService.get(setting.getSettingId());
                if (null != processSetting) {
                    processSetting.setStatus(setting.getStatus());
                    processSetting.setModule(setting.getModule());
                    processSetting.setRemark(setting.getRemark());
                    processSetting.setOrgid(new BigDecimal(orgid));
                    processSetting.setCompanyid(staff.getCurrentOrg().getOrgid());
                    processSettingService.update(processSetting);
                    return JsonBean.success();
                } else {
                    return JsonBean.error();
                }
            } else {
                setting.setStatus("ON");
                setting.setOrgid(new BigDecimal(orgid));
                setting.setCompanyid(staff.getCurrentOrg().getOrgid());
                processSettingService.savemerge(setting);
                return JsonBean.success();
            }
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            if (null != setting.getSettingId()) {
                ProcessSettingMySql processSetting = processSettingService.getMy(setting.getSettingId());
                if (null != processSetting) {
                    processSetting.setStatus(setting.getStatus());
                    processSetting.setModule(setting.getModule());
                    processSetting.setRemark(setting.getRemark());
                    processSetting.setOrgid(new BigDecimal(orgid));
                    processSetting.setCompanyid(staff.getCurrentOrg().getOrgid());
                    ProcessSetting processSetting1 = new ProcessSetting();
                    BeanUtils.copyProperties(processSetting, processSetting1);
                    processSettingService.update(processSetting1);
                    return JsonBean.success();
                } else {
                    return JsonBean.error();
                }
            } else {
                setting.setStatus("ON");
                setting.setOrgid(new BigDecimal(orgid));
                setting.setCompanyid(staff.getCurrentOrg().getOrgid());
                processSettingService.savemerge(setting);
                return JsonBean.success();
            }
        }
    }


    @RequestMapping(value = "/processdelete", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "流程定义-删除")
    public @ResponseBody
    String processdelete(ProcessSetting setting, BigDecimal settingId) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (null != settingId) {
                ProcessSetting processSetting = processSettingService.get(settingId);
                if (null != processSetting) {
                    processSettingService.delete(processSetting.getSettingId());
                    return JsonBean.success();
                } else {
                    return JsonBean.error();
                }
            } else {
                return JsonBean.error();
            }
        } else {
            if (null != settingId) {
                ProcessSettingMySql processSetting = processSettingService.getMy(settingId);
                if (null != processSetting) {
                    processSettingService.delete(processSetting.getSettingId());
                    return JsonBean.success();
                } else {
                    return JsonBean.error();
                }
            } else {
                return JsonBean.error();
            }
        }
    }


    @ResponseBody
    @ApiOperation(value = "查看流程定义")
    @RequestMapping(value = "/definition_list", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    public String findProcessDefinition(@ApiParam(required = true, defaultValue = "1")@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
                                        @ApiParam(required = true, defaultValue = "10")@RequestParam(value = "pageSize", required = false) Integer pageSize,
                                        @ApiParam(name = "definitionName", value = "definitionName", required = false) @RequestParam(value = "definitionName", required = true) String definitionName) {
        String result = null;
        String  sjprocessid="SJ_JHGL/SJ_JYDA/SJ_XMGL/SJ_JHTZD/SJ_SJBG/SJ_SSQRS/SJ_DGFH/SJ_SJBGFH/SJ_ZQYJ";
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>();
			if(sjprocessid.contains(definitionName)) {
				ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery()
						.orderByProcessDefinitionVersion().desc();
				if (null != definitionName && !"".equals(definitionName)) {
					query.processDefinitionKey(definitionName);
				}
				Long rowCount = query.count();
				pageInfo.setPageSize(10);
				pageInfo.setCurrentPage(1);
				pageInfo.setTotalRecord(rowCount.intValue());
				List<ProcessDefinition> list = query.listPage((pageNumber - 1) * pageSize, pageSize);
				
				List<Map<String, Object>> pd = new ArrayList<Map<String, Object>>();
				for (ProcessDefinition processDefinition : list) {
					Map<String, Object> values = new HashMap<String, Object>();
					values.put("id", processDefinition.getId());
					values.put("name", processDefinition.getName());
					values.put("key", processDefinition.getKey());
					values.put("version", processDefinition.getVersion());
					values.put("resourceName", processDefinition.getResourceName());
					values.put("deploymentId", processDefinition.getDeploymentId());
					values.put("DiagramResourceName", processDefinition.getDiagramResourceName());
					values.put("suspended", processDefinition.isSuspended());
					pd.add(values);
				}
				pageInfo.setTlist(pd);
			}else {
				pageInfo = HttpClient.findByProcess(pageNumber, pageBean.getPageSize(), definitionName);
			}
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        Map<String, Object> dataMap = new HashMap<String, Object>(0);
        dataMap.put("pageInfo", pageInfo);
        resultMap.put("code", "1");
        resultMap.put("msg", "数据访问成功");
        resultMap.put("data", dataMap);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    //添加流程
    @RequestMapping(value = "/adddeploymentzip", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    public String adddeploymentzip(HttpServletRequest request,MultipartFile file, String processname, String processid) throws IOException {
        String attPath = "";
        if (file == null) {
            return JsonBean.error("无上传文件！");
        }
        String  sjprocessid="SJ_JHGL/SJ_JYDA/SJ_XMGL/SJ_JHTZD/SJ_SJBG/SJ_SSQRS/SJ_DGFH/SJ_SJBGFH/SJ_ZQYJ";
        try {
			if(sjprocessid.contains(processid)) {
				if (file != null) {
					String myFileName = file.getOriginalFilename();
					File f = null;
					if (!file.equals("") && file.getSize() > 0L) {
						InputStream ins = file.getInputStream();
						f = new File(file.getOriginalFilename());
						
						try {
							OutputStream os = new FileOutputStream(f);
							//int bytesRead = false;
							byte[] buffer = new byte[8192];
							
							int bytesRead;
							while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
								os.write(buffer, 0, bytesRead);
							}
							os.close();
							ins.close();
						} catch (Exception var18) {
							var18.printStackTrace();
						}
					} else {
						file = null;
					}
					if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
						if (file != null) {
							// 取得当前上传文件的文件名称
							//String myFileName = file.getOriginalFilename();
							InputStream in = file.getInputStream();
							DeploymentBuilder depBuilder = repositoryService.createDeployment().name(processid)
									.addZipInputStream(new ZipInputStream(in));
							 Deployment deploy = depBuilder.deploy();
							//deployment(myFileName);
							 System.out.println("流程ID"+deploy.getId());
						}
					} else {
						boolean process = HttpClient.updateProcess(f);
						if (file != null) {
							// 取得当前上传文件的文件名称
							//String myFileName = file.getOriginalFilename();
							InputStream in = file.getInputStream();
							DeploymentBuilder depBuilder = repositoryService.createDeployment().name(processid)
									.addZipInputStream(new ZipInputStream(in));
							 Deployment deploy = depBuilder.deploy();
							//deployment(myFileName);
							 System.out.println("流程ID"+deploy.getId());
						}
					}
				}
				
			}else {
			    if (file != null) {
			        String myFileName = file.getOriginalFilename();
			        File f = null;
			        if (!file.equals("") && file.getSize() > 0L) {
			            InputStream ins = file.getInputStream();
			            f = new File(file.getOriginalFilename());

			            try {
			                OutputStream os = new FileOutputStream(f);
			                //int bytesRead = false;
			                byte[] buffer = new byte[8192];

			                int bytesRead;
			                while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
			                    os.write(buffer, 0, bytesRead);
			                }
			                os.close();
			                ins.close();
			            } catch (Exception var18) {
			                var18.printStackTrace();
			            }
			        } else {
			            file = null;
			        }
			        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			            boolean process = HttpClient.updateProcess(f);
			            if (process) {
			                File zhfile = TblAnalysisXml.zhfile(f);
			                List<TblProcessAnalysis> list = TblAnalysisXml.analsisiXml(zhfile, processid, processname);
			                if (list != null && list.size() > 0) {
			                    Iterator var25 = list.iterator();

			                    while (var25.hasNext()) {
			                        TblProcessAnalysis tblAnalysis = (TblProcessAnalysis) var25.next();
			                        tblAnalysis.setProcessname(processid);
			                        this.tblProcessAnalysisService.updateSetting(tblAnalysis);
			                    }
			                }

			                System.out.println("上传成功！");
			            }
			        } else {
			            boolean process = HttpClient.updateProcess(f);
			            if (process) {
			                File zhfile = TblAnalysisXml.zhfile(f);
			                List<TblProcessAnalysis> list = TblAnalysisXml.analsisiXml(zhfile, processid, processname);
			                if (list != null && list.size() > 0) {
			                    Iterator var25 = list.iterator();

			                    while (var25.hasNext()) {
			                        TblProcessAnalysisMySql tblAnalysis = (TblProcessAnalysisMySql) var25.next();
			                        tblAnalysis.setProcessname(processid);
			                        this.tblProcessAnalysisService.updateMySqlSetting(tblAnalysis);
			                    }
			                }

			                System.out.println("上传成功！");
			            }
			        }
			    }
			}
		} catch (IOException e) {
	        return JsonBean.error();
		}

        return JsonBean.success();
    }

    @Resource
    private RuntimeService runtimeService;

    @RequestMapping(value = "/processInstance", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "流程定义-流程实例")
    public String processInstance(@ApiParam(name = "module", value = "module", required = false) String module,
                                  @ApiParam(name = "processDefinitionId", value = "processDefinitionId", required = false) String processDefinitionId,
                                  @RequestParam(required = false, defaultValue = "1") Integer pageNumber,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        String result = null;
        ProcessInstanceQuery query = runtimeService
                .createProcessInstanceQuery();
        if (null != processDefinitionId && !"".equals(processDefinitionId.trim())) {
            query.processDefinitionId(processDefinitionId);
        }
        Long rowCount = query.count();
        List<ProcessInstance> list = query.listPage((pageNumber - 1) * pageSize, pageSize);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>();
        pageInfo.setPageSize(10);
        pageInfo.setCurrentPage(1);
        pageInfo.setTotalRecord(rowCount.intValue());
        List<Map<String, Object>> pd = new ArrayList<Map<String, Object>>();
        for (ProcessInstance instance : list) {
            Map<String, Object> values = new HashMap<String, Object>();
            values.put("id", instance.getId());
            values.put("processDefinitionId", instance.getProcessDefinitionId());
            values.put("businessKey", instance.getBusinessKey());
            values.put("isEnded", instance.isEnded());
            values.put("isSuspended", instance.isSuspended());
            pd.add(values);
        }
        pageInfo.setTlist(pd);
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        Map<String, Object> dataMap = new HashMap<String, Object>(0);
        dataMap.put("pageInfo", pageInfo);
        dataMap.put("processDefinitionId", processDefinitionId);
        dataMap.put("module", module);
        resultMap.put("code", "1");
        resultMap.put("msg", "数据访问成功");
        resultMap.put("data", dataMap);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    @RequestMapping(value = "/historyProcess", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "流程定义-历史流程")
    public String historyProcess(@ApiParam(name = "module", value = "module", required = false) String module,
                                 @ApiParam(name = "processDefinitionId", value = "processDefinitionId", required = false) String processDefinitionId,
                                 @RequestParam(required = false, defaultValue = "1") Integer pageNumber,
                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        String result = null;
        HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
        query = query.finished();
        if (null != processDefinitionId && !"".equals(processDefinitionId.trim())) {
            query.processDefinitionId(processDefinitionId);
        }
        Long rowCount = query.count();
        List<HistoricProcessInstance> list = query.listPage((pageNumber - 1) * pageSize, pageSize);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>();
        pageInfo.setPageSize(pageSize);
        pageInfo.setCurrentPage(pageNumber);
        pageInfo.setTotalRecord(rowCount.intValue());
        List<Map<String, Object>> pd = new ArrayList<Map<String, Object>>();
        for (HistoricProcessInstance instance : list) {
            Map<String, Object> values = new HashMap<String, Object>();
            values.put("id", instance.getId());
            values.put("businessKey", instance.getBusinessKey());
            values.put("processDefinitionId", instance.getProcessDefinitionId());
            values.put("startTime", instance.getStartTime());
            values.put("endTime", instance.getEndTime());
            values.put("durationInMillis", instance.getDurationInMillis());
            values.put("endActivityId", instance.getEndActivityId());
            values.put("startActivityId", instance.getStartActivityId());
            pd.add(values);
        }
        pageInfo.setTlist(pd);
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        Map<String, Object> dataMap = new HashMap<String, Object>(0);
        dataMap.put("pageInfo", pageInfo);
        dataMap.put("processDefinitionId", processDefinitionId);
        dataMap.put("module", module);
        resultMap.put("code", "1");
        resultMap.put("msg", "数据访问成功");
        resultMap.put("data", dataMap);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }

    @PostMapping(value = "/history_delete")
    @ApiOperation(value = "历史流程-删除")
    public String history_delete(String[] ids, String processDefinitionId, String module) {
        for (String id : ids) {
            historyService.deleteHistoricProcessInstance(id);
        }
        return JsonBean.success();
    }

    /**
     * 删除
     * 流程定义
     *
     * @return
     */
    @PostMapping(value = "/definition_delete")
    @ApiOperation(value = "查看流程定义-删除")
    public String definition_delete(String[] ids, String definitionName) {
        for (String id : ids) {
            //id：流程定义的id
            //true：级联删除，删除流程定义会自动删除流程定义对应的流程实例。。。等
            repositoryService.deleteDeployment(id, true);
        }

        return JsonBean.success();
    }

//
//    @RequestMapping(value = "nbsj/gz_lct", method = {RequestMethod.POST})
//    @ApiOperation(value = "流程定义-流程实例-流程跟踪")
//    public String gz_lct(String cyId) {
//        String result = null;
//        Map<String,Object> resultMap = new HashMap<String, Object>(0);
//        Map<String,Object> dataMap = new HashMap<String, Object>(0);
//        logger.info("跟踪流程图");
//        TblCirculation cy = tblCirculationService.selectCirculation(cyId);
//        dataMap.put("cy",cy);
////        if(cy.getDefinitionid().equals("cyhw_jjhtjc")){
////
////        }
//        dataMap.put("url",HttpClient.jkurl+cy.getBusinesskey());
//        resultMap.put("code", "1");
//        resultMap.put("msg", "数据访问成功");
//        resultMap.put("data", dataMap);
//        resultMap.put("code", "1");
//        resultMap.put("msg", "数据访问成功");
//        resultMap.put("data", dataMap);
//        JSONObject jsonObj = new JSONObject(resultMap);
//        result = jsonObj.toString();
//        return result;
//    }


    //流程跟踪
//    @RequestMapping(value = "/process/picture", method = {RequestMethod.POST})
//    public void getbuttons(@ApiParam(name="definitionId",value="definitionId",required=false)String definitionId,
//                           @ApiParam(name="businessKey",value="businessKey",required=false)String businessKey, HttpServletResponse response) {
//        if (null != definitionId && !"".equals(definitionId.trim())) {
//            ((ProcessDefinition)this.repositoryService.createProcessDefinitionQuery().processDefinitionId(definitionId).singleResult()).getKey();
//        }
//
//        ProcessInstance processInstance = (ProcessInstance)this.runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(businessKey).singleResult();
//        BpmnModel bpmnModel = this.repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
//        List<Execution> executions = this.runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
//        List<String> activeIds = new ArrayList();
//        Iterator var8 = executions.iterator();
//
//        while(var8.hasNext()) {
//            Execution exe = (Execution)var8.next();
//            List<String> list = this.runtimeService.getActiveActivityIds(exe.getId());
//            activeIds.addAll(list);
//        }
//
//        List<HistoricActivityInstance> historicActivityInstances = this.historyService.createHistoricActivityInstanceQuery().finished().processInstanceId(processInstance.getId()).list();
//        List<String> historyIds = new ArrayList();
//        Iterator var12 = historicActivityInstances.iterator();
//
//        while(var12.hasNext()) {
//            HistoricActivityInstance historicActivityInstance = (HistoricActivityInstance)var12.next();
//            historyIds.add(historicActivityInstance.getActivityId());
//        }
//
//        historyIds.removeAll(activeIds);
//        this.processEngineConfiguration = this.processEngine.getProcessEngineConfiguration();
//        Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl)this.processEngineConfiguration);
//        ProcessDiagramGenerator ge = new DefaultProcessDiagramGenerator();
//        //ProcessDiagramGenerator diagramGenerator = this.processEngineConfiguration.getProcessDiagramGenerator();
//        InputStream in = ge.generateDiagram(bpmnModel, "png", activeIds, historyIds, "宋体", "宋体", (ClassLoader)null, 1.0D);
//       FileCopyUtils.copy(in, response.getOutputStream());
//
//    }


//    @RequestMapping(value = "/findOrganizationByTreeNbkz", method = {RequestMethod.POST})
//    @ApiOperation(value = "公司及下属部门String")
//    public void findOrganizationByTreeNukz(HttpServletRequest request, HttpServletResponse response,
//                                           HttpSession session, String orgid) {
//        TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
//        String str = request.getParameter("str");
//        boolean is = false;
//        if(StringUtils.isNotBlank(str) && str.equals("3")&&StringUtils.isNotBlank(GROUP_STRUCTURE)){
//            is = true;
//        }
//        String orgtree = "";
//        HashMap<String, Object> fields = new HashMap<String, Object>();
//        fields.put("nodeId",attribute.getOrgid().toString());
//        if (is){
//            try {
//                orgtree = HttpClient.request(HttpClient.getDeptString, fields, null);
//                if(!StringUtils.isNotBlank(orgtree)) {
//                    orgtree = tblOrganizaService.findOrgByAllJT(orgid);
//                }
//            } catch (Exception e) {
//                orgtree = tblOrganizaService.findOrgByAllJT(attribute.getOrgid().toString());
//            }
//        } else {
//            try {
//                orgtree = HttpClient.request(HttpClient.getDeptString, fields, null);
//                if(!StringUtils.isNotBlank(orgtree)) {
//                    orgtree = tblOrganizaService.findOrgByAll(attribute.getOrgid().toString());
//                }
//            } catch (Exception e) {
//                orgtree = tblOrganizaService.findOrgByAll(attribute.getOrgid().toString());
//            }
//        }
//
//        PrintWriter out = null;
//        try {
//            response.setCharacterEncoding("UTF-8");
//            out = response.getWriter();
//            out.write("[" + orgtree + "]");
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            out.flush();
//            out.close();
//        }
//    }


    @RequestMapping(value = "/processInstance_delete", method = {RequestMethod.POST})
    public String processInstance_delete(String[] ids) {
        return processSettingService.deleteProcessInstance(ids);
    }


    @ResponseBody
    @RequestMapping(value = "/data/excetuImport", method = {RequestMethod.POST})
    @ApiOperation(value = "导入财务数据excel文档 , type = 1 导入信息为科目信息；2凭证相关的信息 3.科目的期初余额表")
    public Integer importDataNew(HttpServletRequest request, HttpServletResponse response,
                                 @RequestParam(value = "accFile", required = false) MultipartFile accFile, @RequestParam(value = "accYear", required = false, defaultValue = "") String accYear,
                                 @RequestParam(value = "pzFile", required = false) MultipartFile pzFile, @RequestParam(value = "pzYear", required = false, defaultValue = "") String pzYear,
                                 @RequestParam(value = "balFile", required = false) MultipartFile balFile, @RequestParam(value = "balYear", required = false, defaultValue = "") String balYear
    ) {
        response.setHeader("Access-Control-Allow-Origin", "*"); //?处理ajax跨域问题 或 ?处理返回前台JSON格式数据问题
        Integer result = -1;
        Integer type = 0;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
            try {
                if (accFile != null) {
                    type = 1;
                    HashMap<String, ArrayList<String[]>> hashMap = ExcelUtil.analysisFile(accFile);
                    result = this.tblOrgExcelService.importFinancData(hashMap, accYear, type, organization);
                }
                if (pzFile != null) {
                    type = 2;
                    HashMap<String, ArrayList<String[]>> hashMap = ExcelUtil.analysisFile(pzFile);
                    result = this.tblOrgExcelService.importFinancData(hashMap, pzYear, type, organization);
                }
                if (balFile != null) {
                    type = 3;
                    HashMap<String, ArrayList<String[]>> hashMap = ExcelUtil.analysisFile(balFile);
                    result = this.tblOrgExcelService.importFinancData(hashMap, balYear, type, organization);
                }
            } catch (OldExcelFormatException excelFormatException) {
                switch (type) {
                    case 1:
                        result = -2;
                        break;
                    case 2:
                        result = -3;
                        break;
                    case 3:
                        result = -4;
                        break;
                    default:
                        break;
                }
                excelFormatException.printStackTrace();
            } catch (NotOLE2FileException notOLE2FileException) {
                switch (type) {
                    case 1:
                        result = -6;
                        break;
                    case 2:
                        result = -7;
                        break;
                    case 3:
                        result = -8;
                        break;
                    default:
                        break;
                }
                notOLE2FileException.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            TblOrganizationMySql organization = (TblOrganizationMySql) request.getSession().getAttribute("hbOrgEntity");
            try {
                if (accFile != null) {
                    type = 1;
                    HashMap<String, ArrayList<String[]>> hashMap = ExcelUtil.analysisFile(accFile);
                    result = this.tblOrgExcelService.importMySqlFinancData(hashMap, accYear, type, organization);
                }
                if (pzFile != null) {
                    type = 2;
                    HashMap<String, ArrayList<String[]>> hashMap = ExcelUtil.analysisFile(pzFile);
                    result = this.tblOrgExcelService.importMySqlFinancData(hashMap, pzYear, type, organization);
                }
                if (balFile != null) {
                    type = 3;
                    HashMap<String, ArrayList<String[]>> hashMap = ExcelUtil.analysisFile(balFile);
                    result = this.tblOrgExcelService.importMySqlFinancData(hashMap, balYear, type, organization);
                }
            } catch (OldExcelFormatException excelFormatException) {
                switch (type) {
                    case 1:
                        result = -2;
                        break;
                    case 2:
                        result = -3;
                        break;
                    case 3:
                        result = -4;
                        break;
                    default:
                        break;
                }
                excelFormatException.printStackTrace();
            } catch (NotOLE2FileException notOLE2FileException) {
                switch (type) {
                    case 1:
                        result = -6;
                        break;
                    case 2:
                        result = -7;
                        break;
                    case 3:
                        result = -8;
                        break;
                    default:
                        break;
                }
                notOLE2FileException.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }

    private ServletConfig config;

    @Override
    public void setServletConfig(ServletConfig servletConfig) {
        this.config = servletConfig;
    }

    @RequestMapping(value = "/org", method = {RequestMethod.POST})
    @ApiOperation(value = "机构管理-组织架构")
    public String org(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("common/zzjg/organ");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("msg", "访问成功");
        String result = null;
        JSONObject jsonObjectMv = new JSONObject(resultMap);
        result = jsonObjectMv.toString();
        return result;
    }


    @RequestMapping(value = "/loginTypeList", method = {RequestMethod.POST})
    @ApiOperation(value = "登录页列表")
    public String loginTypeList(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblLoginTypeService.findAll(token, staffId, pageNumber, pageSize);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping(value = "/loginType_save", method = {RequestMethod.POST})
    @ApiOperation(value = "登录页管理--保存")
    public String loginType_save(HttpServletRequest request, TblLoginType logintype,
                                 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                 @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId
    ) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            try {
                if (logintype.getLoginid() != null) {
                    TblLoginType findByid = tblLoginTypeService.findByid(logintype.getLoginid().toString());
                    logintype.setOrgid(staff.getCurrentOrg().getOrgid().toString());
                    logintype.setLoginid(new BigDecimal(findByid.getLoginid().toString()));
                    tblLoginTypeService.updatetblLoginType(logintype);

                } else {
                    logintype.setOrgid(staff.getCurrentOrg().getOrgid().toString());
                    tblLoginTypeService.save(logintype);
                }
                resultMap.put("code", "1");
                resultMap.put("msg", "成功");
                resultMap.put("data", logintype);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            try {
                if (logintype.getLoginid() != null) {
                    TblLoginTypeMySql findByid = tblLoginTypeService.findByMySqlid(logintype.getLoginid().toString());
                    logintype.setOrgid(staff.getCurrentOrg().getOrgid().toString());
                    logintype.setLoginid(new BigDecimal(findByid.getLoginid().toString()));
                    TblLoginTypeMySql typeMySql = new TblLoginTypeMySql();
                    BeanUtils.copyProperties(logintype, typeMySql);
                    tblLoginTypeService.updateMySqltblLoginType(typeMySql);

                } else {
                    logintype.setOrgid(staff.getCurrentOrg().getOrgid().toString());
                    TblLoginTypeMySql typeMySql = new TblLoginTypeMySql();
                    BeanUtils.copyProperties(logintype, typeMySql);
                    tblLoginTypeService.saveMySql(typeMySql);
                }
                resultMap.put("code", "1");
                resultMap.put("msg", "成功");
                resultMap.put("data", logintype);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }

    @RequestMapping(value = "/loginType_modi", method = {RequestMethod.POST})
    @ApiOperation(value = "登录页管理修改查询登录页信息")
    public String loginType_modi(@RequestParam(value = "loginid", required = false) String loginid) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblLoginTypeService.findByLoginId(loginid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping(value = "/loginType_del", method = {RequestMethod.POST})
    @ApiOperation(value = "登录页管理-删除")
    public String loginType_del(HttpServletRequest request,
                                @RequestParam(value = "loginid", required = true) String loginid) {

        String result = null;
        try {
            Map<String, Object> resultMap = this.tblLoginTypeService.del(loginid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping(value = "/videoType/list", method = {RequestMethod.POST})
    @ApiOperation(value = "课程类别列表")
    public String nbsjTempleTypeList(HttpServletRequest request,
                                     @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                     @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {

        String result = null;
        Map<String, Object> resultMap = this.tblVideoTypeService.findAll(token, staffId, pageNumber, pageSize);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    @ApiOperation(value = "课程类别保存")
    @RequestMapping(value = "/videoType_save", method = {RequestMethod.POST})
    public @ResponseBody
    String sjtype_save(HttpServletRequest request, TblVideoType tnt,
                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                       @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String type = tblVideoTypeService.save(tnt, token, staffId);
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            resultMap.put("data", type);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblVideoTypeMySql tntMySql = new TblVideoTypeMySql();
            BeanUtils.copyProperties(tnt, tntMySql);
            String type = tblVideoTypeService.saveMySql(tntMySql, token, staffId);
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            resultMap.put("data", type);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @ApiOperation(value = "课程类别修改")
    @RequestMapping(value = "/videoType_update", method = {RequestMethod.POST})
    public String qxbz_update(HttpServletRequest request,
                              @RequestParam(value = "selectid", required = true) String selectid) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblVideoTypeService.findByid(selectid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @ResponseBody
    @ApiOperation(value = "课程类别删除")
    @RequestMapping(value = "/videoType_delete", method = {RequestMethod.POST})
    public String qxbz_del(HttpServletRequest request,
                           @RequestParam(value = "typeId", required = true) String typeId) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (typeId != null && !"".equals(typeId)) {
            tblVideoTypeService.deleteById(typeId);
            resultMap.put("code", "1");
            resultMap.put("msg", "3");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
        resultMap.put("code", "2");
        resultMap.put("msg", "9");
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    @ApiOperation(value = "课程维护列表")
    @RequestMapping(value = "/videolist", method = {RequestMethod.POST})
    public String videolist(String coursename1, String coursetype1,
                            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                            @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.courseService.courseList(pageNumber, pageSize, token, staffId, coursename1, coursetype1);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "课程维护新增页面")
    @RequestMapping(value = "/video_add", method = {RequestMethod.POST})
    public String videoadd(String id, String pid, String type,
                           @RequestParam(value = "leveltype", required = false) String leveltype,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                           @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                           @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblVideoTypeService.findAll(token, staffId);
            if (choiceSearch == null || "".equals(choiceSearch)) {
                choiceSearch = "hide";
            }
            resultMap.put("choiceSearch", choiceSearch);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "课程维护修改页面")
    @RequestMapping(value = "/video_videomodi", method = {RequestMethod.POST})
    public String videomodi(@RequestParam(value = "id", required = false) String id,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                            @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                            @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String result = null;
            try {
                TblCourse tblCourse = courseService.geTblCourse(id);
                Map<String, Object> resultMap = this.tblVideoTypeService.findAll(token, staffId);
                if (choiceSearch == null || "".equals(choiceSearch)) {
                    choiceSearch = "hide";
                }
                resultMap.put("choiceSearch", choiceSearch);
                resultMap.put("tblCourse", tblCourse);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            String result = null;
            try {
                TblCourseMySql tblCourse = courseService.geTblCourseMySql(id);
                Map<String, Object> resultMap = this.tblVideoTypeService.findAll(token, staffId);
                if (choiceSearch == null || "".equals(choiceSearch)) {
                    choiceSearch = "hide";
                }
                resultMap.put("choiceSearch", choiceSearch);
                resultMap.put("tblCourse", tblCourse);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    //    @ApiOperation(value="课程维护-保存并跳转修改页面")
//    @RequestMapping(value = "/video_save",method = {RequestMethod.POST} )
//    public @ResponseBody String video_save(HttpServletRequest request,TblCourse tblCourse,
//                                           @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token,
//                                           @ApiParam(name="staffId",value="登录用户主键",required=false)String staffId) {
//        //MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;// request强制转换注意
//        //MultipartFile multipartFile = mRequest.getFile("file");
//        String result = null;
//        Map<String,Object> resultMap = new HashMap<String, Object>(0);
//        Jedis jedis = null;
//        if(token == null && staffId == null) {
//            return null;
//        }
//        if(token == null && staffId != null) {
//            jedis = JedisUtil.getJedis();
//            token = jedis.get(staffId);
//        }
//        Claims claims = JwtUtils.parseJwt(token);
//        Object object = claims.get("staffInfo");
//        net.sf.json.JSONObject objJson = net.sf.json.JSONObject.fromObject(object);
//        TblStaff staff = (TblStaff) net.sf.json.JSONObject.toBean(objJson,TblStaff.class);
//        tblCourse.setOrgid(staff.getCurrentOrg().getOrgid());
//        tblCourse.setUserid(staff.getStaffid());
//        //图片上传
//        String message = "";
//        FileEntity2 entity = new FileEntity2();
//        FileUploadTool fileUploadTool = new FileUploadTool();
//        try {
//            //模块
//            TblVideoType findByName = tblVideoTypeService.findByName(tblCourse.getCoursetype());
//            tblCourse.setType(findByName.getType());
//            //String id = tblCourse.getCourseid().toString();
//            if(StringUtils.isNotBlank(tblCourse.getCourseid().toString())) {
//                TblCourse geTblCourse = courseService.geTblCourse(tblCourse.getCourseid().toString());
////                entity = fileUploadTool.createFile(file, request);
//                // todo
//                // 相对路径
//                String path = fileManager.upload(file);
//                entity.setType(".jpg");//扩展名
//                entity.setSize("");//
//                entity.setPath(path);
//                entity.setTitleOrig("");
//                entity.setTitleAlter("");
//                entity.setVideoFirstPicurl("");
//                Timestamp timestamp = new Timestamp(System.currentTimeMillis());
//                entity.setUploadTime(timestamp);
//                // todo
//                if (entity != null) {
//                    message = "上传成功";
//                    tblCourse.setPicurl(path);
//                }else {
//                    tblCourse.setPicurl(geTblCourse.getPicurl());
//                }
//                tblCourse.setCreateDate(new Date());
//                tblCourse.setCourseid(new BigDecimal(tblCourse.getCourseid().toString()));
//                courseService.updatetblCourse(tblCourse);
//            }else {
//                //entity = fileUploadTool.createFile(file, request);
//                String path = fileManager.upload(file);
//                if (entity != null) {
//                    message = "上传成功";
//                    tblCourse.setPicurl(path);
//                }
//                tblCourse.setCreateDate(new Date());
//                courseService.savetblCourse(tblCourse);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        resultMap.put("code", "1");
//        resultMap.put("msg", "成功");
//        resultMap.put("data", tblCourse.getCourseid());
//        JSONObject jsonObj = new JSONObject(resultMap);
//        result = jsonObj.toString();
//        return result;
//    }
    @ApiOperation(value = "课程维护-保存并跳转修改页面")
    @RequestMapping(value = "/video_save", method = {RequestMethod.POST})
    public @ResponseBody
    String video_save(HttpServletRequest request, TblCourse tblCourse,
                      @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                      @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            tblCourse.setOrgid(staff.getCurrentOrg().getOrgid());
            tblCourse.setUserid(staff.getStaffid());
            try {
                //模块
                TblVideoType findByName = tblVideoTypeService.findByName(tblCourse.getCoursetype());
                tblCourse.setType(findByName.getType());
                if (tblCourse.getCourseid() != null) {
                    TblCourse geTblCourse = courseService.geTblCourse(tblCourse.getCourseid().toString());
                    tblCourse.setCreateDate(new Date());
                    tblCourse.setCourseid(new BigDecimal(tblCourse.getCourseid().toString()));
                    courseService.updatetblCourse(tblCourse);
                } else {
                    tblCourse.setCreateDate(new Date());
                    courseService.savetblCourse(tblCourse);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            resultMap.put("data", tblCourse.getCourseid());
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            tblCourse.setOrgid(staff.getCurrentOrg().getOrgid());
            tblCourse.setUserid(staff.getStaffid());
            try {
                //模块
                TblVideoTypeMySql findByName = tblVideoTypeService.findByMySqlName(tblCourse.getCoursetype());
                tblCourse.setType(findByName.getType());
                if (tblCourse.getCourseid() != null) {
                    TblCourseMySql geTblCourse = courseService.geTblCourseMySql(tblCourse.getCourseid().toString());
                    tblCourse.setCreateDate(new Date());
                    tblCourse.setCourseid(new BigDecimal(tblCourse.getCourseid().toString()));
                    TblCourseMySql tblCourseMySql = new TblCourseMySql();
                    BeanUtils.copyProperties(tblCourse, tblCourseMySql);
                    courseService.updateMySqltblCourse(tblCourseMySql);
                } else {
                    tblCourse.setCreateDate(new Date());
                    TblCourseMySql tblCourseMySql = new TblCourseMySql();
                    BeanUtils.copyProperties(tblCourse, tblCourseMySql);
                    courseService.saveMySqltblCourse(tblCourseMySql);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            resultMap.put("code", "1");
            resultMap.put("msg", "成功");
            resultMap.put("data", tblCourse.getCourseid());
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @ApiOperation(value = "课程维护-删除判断")
    @RequestMapping(value = "/video/deletes", method = {RequestMethod.POST})
    public @ResponseBody
    String video_delete(HttpServletRequest request,
                        @ApiParam(value = "pid", required = false) String pid) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (pid != null && !"".equals(pid)) {
                List<TblCourse> list = courseService.findByFatherid(pid);
                resultMap.put("code", "1");
                resultMap.put("msg", "成功");
                resultMap.put("data", list.size() + "");
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
                return result;
            } else {
                resultMap.put("code", "1");
                resultMap.put("msg", "");
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
                return result;
            }
        } else {
            if (pid != null && !"".equals(pid)) {
                List<TblCourseMySql> list = courseService.findByMySqlFatherid(pid);
                resultMap.put("code", "1");
                resultMap.put("msg", "成功");
                resultMap.put("data", list.size() + "");
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
                return result;
            } else {
                resultMap.put("code", "1");
                resultMap.put("msg", "");
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
                return result;
            }
        }
    }

    @ApiOperation(value = "课程维护-删除")
    @RequestMapping(value = "/video_del", method = {RequestMethod.POST})
    public String video_del(HttpServletRequest request, String[] selectedId) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        try {
            for (int i = 0; i < selectedId.length; i++) {
                resultMap = this.courseService.deletetblCourse(selectedId[i]);
            }
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @ApiOperation(value = "信息查询-充值记录列表")
    @RequestMapping(value = "/deposit_money", method = {RequestMethod.POST})
    public String deposit_money(HttpServletRequest request, TblYyUserOrder yuo,
                                @ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Map<String, Object> resultMap = this.tblYyUserOrderService.selectPageInfoList(token, staffId, pageNumber, pageSize, yuo);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblYyUserOrderMySql yuoMySql = new TblYyUserOrderMySql();
                BeanUtils.copyProperties(yuo, yuoMySql);
                Map<String, Object> resultMap = this.tblYyUserOrderService.selectMySqlPageInfoList(token, staffId, pageNumber, pageSize, yuoMySql);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @ApiOperation(value = "信息查询-费用标准")
    @RequestMapping(value = "/price_cost", method = {RequestMethod.POST})
    public String price_cost(HttpServletRequest request, Find find,
                             @ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                             @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Map<String, Object> resultMap = this.tblyypriceService.findListPage(find, token, staffId, pageNumber, pageSize);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                Map<String, Object> resultMap = this.tblyypriceService.findMySqlListPage(find, token, staffId, pageNumber, pageSize);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @ApiOperation(value = "信息查询-统计费用")
    @RequestMapping(value = "/price_company", method = {RequestMethod.POST})
    public String price_company(HttpServletRequest request, TblYyUserQuery yuq,
                                @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        logger.info("查询公司访问用友接口次数");
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Map<String, Object> resultMap = this.tblYyOrgDepositService.findCostPircePageInfo(pageNumber, pageSize, yuq, token, staffId);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblYyUserQueryMySql yuqMySql = new TblYyUserQueryMySql();
                BeanUtils.copyProperties(yuq, yuqMySql);
                Map<String, Object> resultMap = this.tblYyOrgDepositService.findMySqlCostPircePageInfo(pageNumber, pageSize, yuqMySql, token, staffId);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }

    @ApiOperation(value = "信息查询-查询统计费用明细")
    @RequestMapping(value = "/findQueryRecodeDetail", method = {RequestMethod.POST})
    public String findQueryRecodeDetail(HttpServletRequest request,
                                        @RequestParam(value = "recordId", required = false) Integer recordId) {
        logger.info("查询费用明细");
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblYyUserQueryService.selectUserQueryById(recordId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "信息查询-个人查询")
    @RequestMapping(value = "/select_user", method = {RequestMethod.POST})
    public String sjbbuserLeft_risk(HttpServletRequest request, TblYyUserQuery yuq,
                                    @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                    @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                    @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        logger.info("查询用户访问用友接口次数");
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblYyOrgDepositService.findCostPircePageInfo(pageNumber, pageSize, yuq, token, staffId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


//    @RequestMapping(value = "/downloadTemplate")
//    public ResponseEntity<byte[]> downloadTemplate(HttpServletResponse response,
//                                                   @RequestParam(value = "type", required=false) Integer type,
//                                                   @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token) throws Exception {
//        TblStaffUtil staff =DealUserToken.parseUserToken(token);
//        ClassPathResource cpr = new ClassPathResource("static/");
//        String path = cpr.getPath();
//        String fileName = this.tblFinanceDataService.findModelName(type,staff.getCurrentOrg().getOrgid());
//        if(fileName == null) {
//            return null;
//        }
//        path = path + separator +fileName;
//        File file = new File(path);
//        HttpHeaders headers = new HttpHeaders();
//        String fileName1 = processFileName(request, fileName);// 为了解决中文名称乱码问题
//        headers.setContentDispositionFormData("attachment", fileName1);
//        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//        headers.set("Content-disposition", "attachment;filename=" + fileName1);
//        headers.set("Content-Length", String.valueOf(file.length()));
//        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK);
//    }


    @GetMapping("/mb/download")
    @ApiOperation(value = "数据导入模板")
    public String fileDownLoad(HttpServletResponse response, @RequestParam(value = "type", required = false) Integer type,
                               @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) throws Exception {

        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        String fileName = this.tblFinanceDataService.findModelName(type, staff.getCurrentOrg().getOrgid());
        File file = new File(filepath + '/' + fileName);
        if (!file.exists()) {
            return "下载文件不存在";
        }
        response.reset();
        fileName = response.encodeURL(new String(fileName.getBytes(), "iso8859-1"));//对中文文件名转码
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setCharacterEncoding("GBK");
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName);

        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));) {
            byte[] buff = new byte[1024];
            OutputStream os = response.getOutputStream();
            int i = 0;
            while ((i = bis.read(buff)) != -1) {
                os.write(buff, 0, i);
                os.flush();
            }
        } catch (IOException e) {
            return "下载失败";
        }
        return "下载成功";
    }


    /**
     * 获取项目根路径
     *
     * @return
     */

    private static String getResourceBasePath() {
        // 获取跟目录
        File path = null;
        try {
            path = new File(ResourceUtils.getURL("classpath:").getPath());
        } catch (FileNotFoundException e) {
            // nothing to do
        }
        if (path == null || !path.exists()) {
            path = new File("");
        }

        String pathStr = path.getAbsolutePath();
        // 如果是在eclipse中运行，则和target同级目录,如果是jar部署到服务器，则默认和jar包同级
        pathStr = pathStr.replace("\\target\\classes", "");

        return pathStr;
    }


    @ApiOperation(value = "数据采集-采集配置列表")
    @RequestMapping(value = "/zt/sjcj_list", method = {RequestMethod.POST})
    public String sjcj_list(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                            @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            //数据采集列表
            Map<String, Object> resultMap = tblFinanceDataService.findByCompanyId(pageNumber, token, staffId, pageSize);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "数据采集-采集配置删除")
    @RequestMapping(value = "/zt/sjcj_del", method = {RequestMethod.POST})
    public @ResponseBody
    String sjcj_del(HttpServletRequest request,
                    @RequestParam(value = "orderId", required = false) String orderId) {
        String result = null;
        if (orderId != null && !"".equals(orderId)) {
            Map<String, Object> resultMap = tblFinanceDataService.del(orderId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        }
        return result;
    }


    @ApiOperation(value = "数据采集-采集配置保存")
    @RequestMapping(value = "/zt/sjcj_save", method = {RequestMethod.POST})
    public @ResponseBody
    String sjtype_save(HttpServletRequest request, TblFinanceData tlf,
                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                       @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                       @ApiParam(name = "parseStart", value = "parseStart", required = true) String parseStart,
                       @ApiParam(name = "pendDate", value = "pendDate", required = true) String pendDate,
                       @ApiParam(name = "sid", value = "sid", required = false) String fid) throws Exception {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String tbfinanceDate = tblFinanceDataService.selectDateByCompanyid(request, token, staffId, tlf, parseStart, pendDate, fid);
//            resultMap.put("code", "1");
//            resultMap.put("msg", tbfinanceDate);
//            JSONObject jsonObj = new JSONObject(resultMap);
//            result = jsonObj.toString();
            return tbfinanceDate;
        } else {
            TblFinanceDataMySql tlfMySql = new TblFinanceDataMySql();
            BeanUtils.copyProperties(tlf, tlfMySql);
            String tbfinanceDate = tblFinanceDataService.selectMySqlDateByCompanyid(request, token, staffId, tlfMySql, parseStart, pendDate, fid);
            return tbfinanceDate;
        }
    }

    @ApiOperation(value = "数据采集-采集配置-修改新建单选")
    @RequestMapping(value = "/financial_version_show", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    public void csfa_findOrganizationByTree(HttpServletRequest request, HttpServletResponse response, HttpSession session, String orgid) {
        String str = "";
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblVersion tblVersion = tblVersionService.findbyFid("100");
            List<TblVersion> chil = tblVersionService.selectAllTblVersion();
            //所有财务软件
            List<Node> childDeptList = new ArrayList<Node>();
            for (TblVersion tblVersion2 : chil) {
                Node tree = new Node();
                tree.setId(tblVersion2.getFid().toString());
                tree.setText(tblVersion2.getFvendor());
                tree.setParentId(tblVersion2.getFatherid().toString());
                childDeptList.add(tree);
            }
            List<Node> children = rebuildList2TreeString(childDeptList);
            Node tree = new Node();
            tree.setChildren(children);
            tree.setText(tblVersion.getFvendor());
            tree.setId(tblVersion.getFid().toString());
            str = tree.toString();
            PrintWriter out = null;
            try {
                response.setCharacterEncoding("UTF-8");
                out = response.getWriter();
                out.write("[" + str + "]");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                out.flush();
                out.close();
            }
        } else {
            TblVersionMySql tblVersion = tblVersionService.findbyMySqlFid("100");
            List<TblVersionMySql> chil = tblVersionService.selectAllMySqlTblVersion();
            //所有财务软件
            List<NodeMySql> childDeptList = new ArrayList<NodeMySql>();
            for (TblVersionMySql tblVersion2 : chil) {
                NodeMySql tree = new NodeMySql();
                tree.setId(tblVersion2.getFid().toString());
                tree.setText(tblVersion2.getFvendor());
                tree.setParentId(tblVersion2.getFatherid().toString());
                childDeptList.add(tree);
            }
            List<NodeMySql> children = rebuildMySqlList2TreeString(childDeptList);
            NodeMySql tree = new NodeMySql();
            tree.setChildren(children);
            tree.setText(tblVersion.getFvendor());
            tree.setId(tblVersion.getFid().toString());
            str = tree.toString();
            PrintWriter out = null;
            try {
                response.setCharacterEncoding("UTF-8");
                out = response.getWriter();
                out.write("[" + str + "]");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                out.flush();
                out.close();
            }
        }
    }

    /**
     * 使用递归方法建树
     */
    private static List<Node> rebuildList2TreeString(List<Node> treeNodes) {
        boolean existRootNode = false;
        List<Node> newTree = new ArrayList<Node>();//初始化一个新的列表
        for (Node treeNode : treeNodes) {
            if (isRootNodeString(treeNode, treeNodes)) {//选择根节点数据开始找儿子
                newTree.add(findChildrenString(treeNode, treeNodes));
                existRootNode = true;
            }
        }
        if (!existRootNode) {//也可能大家都是根节点
            return treeNodes;
        }
        return newTree;
    }

    private static List<NodeMySql> rebuildMySqlList2TreeString(List<NodeMySql> treeNodes) {
        boolean existRootNode = false;
        List<NodeMySql> newTree = new ArrayList<NodeMySql>();//初始化一个新的列表
        for (NodeMySql treeNode : treeNodes) {
            if (isMySqlRootNodeString(treeNode, treeNodes)) {//选择根节点数据开始找儿子
                newTree.add(findMySqlChildrenString(treeNode, treeNodes));
                existRootNode = true;
            }
        }
        if (!existRootNode) {//也可能大家都是根节点
            return treeNodes;
        }
        return newTree;
    }

    /**
     * 判断节点是否是根节点
     */
    private static boolean isRootNodeString(Node checkNode, List<Node> treeNodes) {
        for (Node treeNode : treeNodes) {
            if (checkNode.getParentId().equals(treeNode.getId())) {//判断checkNode是不是有爸爸
                return false;
            }
        }
        return true;
    }

    private static boolean isMySqlRootNodeString(NodeMySql checkNode, List<NodeMySql> treeNodes) {
        for (NodeMySql treeNode : treeNodes) {
            if (checkNode.getParentId().equals(treeNode.getId())) {//判断checkNode是不是有爸爸
                return false;
            }
        }
        return true;
    }

    /**
     * 递归查找子节点
     */
    private static Node findChildrenString(Node parentNode, List<Node> treeNodes) {
        List<Node> children = parentNode.getChildren();
        for (Node it : treeNodes) {
            if (parentNode.getId().equals(it.getParentId())) {//找儿子，判断parentNode是不是有儿子
                children.add(findChildrenString(it, treeNodes));
            }
        }
        return parentNode;
    }

    private static NodeMySql findMySqlChildrenString(NodeMySql parentNode, List<NodeMySql> treeNodes) {
        List<NodeMySql> children = parentNode.getChildren();
        for (NodeMySql it : treeNodes) {
            if (parentNode.getId().equals(it.getParentId())) {//找儿子，判断parentNode是不是有儿子
                children.add(findMySqlChildrenString(it, treeNodes));
            }
        }
        return parentNode;
    }


    @ApiOperation(value = "采集配置-修改前查询页面")
    @RequestMapping(value = "/zt/sjcj_modi", method = {RequestMethod.POST})
    public String sjcj_modi(@RequestParam(value = "selectid", required = true) String selectid) throws ParseException {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblFinanceData tblFinanceData = tblFinanceDataService.get(selectid);
            SimpleDateFormat format = new SimpleDateFormat("yyyy");
            Date startdate = format.parse(tblFinanceData.getStartdate().toString());
            Date enddate = format.parse(tblFinanceData.getEnddate().toString());
            resultMap.put("startdate", startdate);
            resultMap.put("enddate", enddate);
            resultMap.put("tlf", tblFinanceData);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblFinanceDataMySql tblFinanceData = tblFinanceDataService.getMySql(selectid);
            SimpleDateFormat format = new SimpleDateFormat("yyyy");
            Date startdate = format.parse(tblFinanceData.getStartdate().toString());
            Date enddate = format.parse(tblFinanceData.getEnddate().toString());
            resultMap.put("startdate", startdate);
            resultMap.put("enddate", enddate);
            resultMap.put("tlf", tblFinanceData);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }

    @ApiOperation(value = "数据采集-采集策略列表")
    @RequestMapping(value = "/zt/getAcInfo", method = {RequestMethod.POST})
    public String getAcInfo(HttpServletRequest request,
                            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                            @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                            @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
                            @RequestParam(value = "typeName", required = false) String typeName,
                            @RequestParam(value = "strType", required = false) String strType,
                            @RequestParam(value = "strVal", required = false) String strVal,
                            @RequestParam(value = "sqlStr", required = false) String sqlStr,
                            @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        try {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("orgId", staff.getCurrentOrg().getOrgid());
            fields.put("pageNumber", pageNumber);
            fields.put("pageSize", pageSize);
            fields.put("typeName", typeName);
            fields.put("strVal", strVal);
            fields.put("strType", strType);
            fields.put("sqlStr", sqlStr);
            String results = HttpClient.request(acurl + "/acquisition/getAcTimeInfo", fields, null);
            //String results = HttpClient.request("http://59.110.222.142:8003/acquisition/getAcTimeInfo", fields, null);
            JSONObject resultjs = JSONObject.parseObject(results);
            PageInfo<TblCwsjDscjInfo> pageInfo = new PageInfo<TblCwsjDscjInfo>();
            if ("true".equals(resultjs.get("result").toString())) {
                pageInfo.setTotalRecord(Integer.parseInt(resultjs.get("count").toString()));
                String list = resultjs.get("list").toString();
                List<TblCwsjDscjInfo> tcdjList = JSONObject.parseArray(list, TblCwsjDscjInfo.class);
                pageInfo.setTlist(tcdjList);
            } else {
                List<TblCwsjDscjInfo> list = new ArrayList<TblCwsjDscjInfo>(0);
                pageInfo.setTotalRecord(0);
                pageInfo.setTlist(list);
            }
            if (resultjs.get("sqlStr") != null) {
                pageInfo.setSqlStr(resultjs.get("sqlStr").toString());
            }
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            resultMap.put("pageInfo", pageInfo);
            //为页面查找区域显隐藏赋值
            if (choiceSearch == null || "".equals(choiceSearch)) {
                choiceSearch = "hide";
            }
            resultMap.put("choiceSearch", choiceSearch);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "数据采集-采集策略新增")
    @RequestMapping(value = "/zt/saveAvTimeInfo", method = {RequestMethod.POST})
    public @ResponseBody
    Integer saveAvTimeInfo(
            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
            @RequestParam(value = "acName", required = true) String acName,
            @RequestParam(value = "hourStr", required = true) String hourStr,
            @RequestParam(value = "weekStr", required = true) String weekStr) {
        try {

            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("orgId", staff.getCurrentOrg().getOrgid().toString());
            fields.put("infoName", acName);
            fields.put("setDate", hourStr);
            fields.put("acWeek", weekStr);
            fields.put("staffId", staff.getStaffid());
            String result = HttpClient.request(acurl + "/acquisition/insertAcTimeInfo", fields, null);
            if (result.indexOf("success") != -1) {
                return 0;
            } else {
                return -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }


    @ApiOperation(value = "数据采集-采集策略-修改查询")
    @RequestMapping(value = "/zt/getAcInfoUnique", method = {RequestMethod.POST})
    public @ResponseBody
    String getAcInfoUnique(
            @RequestParam(value = "infoId", required = true) String infoId) {
        String tcdj = "";
        try {
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("infoId", infoId);
            String result = HttpClient.request(acurl + "/acquisition/selectAcInfoUnique", fields, null);
            JSONObject resultjs = JSONObject.parseObject(result);
            if ("true".equals(resultjs.get("result").toString())) {
                tcdj = resultjs.get("tcdj").toString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tcdj;
    }


    @ApiOperation(value = "数据采集-采集策略-修改保存")
    @RequestMapping(value = "/zt/modifyInfo", method = {RequestMethod.POST})
    public @ResponseBody
    Integer modifyInfo(HttpServletRequest request, TblCwsjDscjInfo tcdj) {
        try {
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("infoId", tcdj.getInfoId());
            fields.put("status", tcdj.getStatus());
            fields.put("setDate", tcdj.getSetDate());
            fields.put("acWeek", tcdj.getAcWeek());
            fields.put("infoName", tcdj.getInfoName());
            String result = HttpClient.request(acurl + "/acquisition/updateAcTimeInfo", fields, null);
            if (result.indexOf("success") != -1) {
                return 0;
            } else {
                return -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }


    @ApiOperation(value = "数据采集-采集策略-删除")
    @RequestMapping(value = "/zt/removeAvTimeInfo", method = {RequestMethod.POST})
    public @ResponseBody
    Integer removeAvTimeInfo(
            @RequestParam(value = "infoStr", required = true) String infoStr) {
        try {
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("infoStr", infoStr);
            String result = HttpClient.request(acurl + "/acquisition/deleteAcTimeInfo", fields, null);
            if (result.indexOf("success") != -1) {
                return 0;
            } else {
                return -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    @ApiOperation(value = "数据采集的采集展现页面")
    @RequestMapping(value = "/show/acquisition", method = {RequestMethod.POST})
    public String showAcquisition(@ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                  @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                  @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                  @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblAcquisitionRecordService.findByPage(pageNumber, pageSize, token, staffId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ResponseBody
    @ApiOperation(value = "数据采集-采集")
    @RequestMapping(value = "/startAcquisition", method = {RequestMethod.POST})
    public String startAcquisition(@ApiParam(value = "startYear", required = true) Integer startYear,
                                   @ApiParam(value = "endYear", required = true) Integer endYear, HttpServletRequest request,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                   @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal orgid = staff.getCurrentOrg().getOrgid();
        BigDecimal staffid = staff.getStaffid();
        String record = "";
        try {
            HashMap<String, Object> fields = new HashMap<String, Object>(0);
            fields.put("startYear", startYear);
            fields.put("endYear", endYear);
            fields.put("orgId", orgid);
            fields.put("staffId", staffid);
            record = HttpClient.request(acurl + "/acquisition/startAcquisitionByOrgId", fields, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return record;
    }

    @ResponseBody
    @ApiOperation(value = "模板下载列表")
    @RequestMapping(value = "/excelimp/kzjz/list", method = {RequestMethod.POST})
    public String kzjz(HttpServletRequest request,
                       @ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                       @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                       @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        Map<String, Object> resultMap = this.tblImplogService.findByTblImplogList(token, staffId, TblImplog.IMPSTATE_KZJZ, pageNumber, pageSize);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    @ApiOperation(value = "模板下载")
    @RequestMapping(value = "/downloadTemplate", method = {RequestMethod.POST})
    public ResponseEntity<byte[]> downloadTemplate(String fileName, HttpServletResponse response) throws IOException {

        //String path = ClassUtils.getDefaultClassLoader().getResource("static").getPath();
        if (fileName.trim().equals("kzjz")) {
            fileName = "内部控制（控制矩阵）导入模板.xls";
        } else if (fileName.trim().equals("nwgd")) {
            fileName = "内部控制（内外规）导入模板.xls";
        } else if (fileName.trim().equals("nbkz")) {
            fileName = "内部控制（基本信息）导入模板.xls";
        } else if (fileName.trim().equals("ng")) {
            fileName = "内部控制（规章制度）导入模板.xls";
        } else if (fileName.trim().equals("wg")) {
            fileName = "内部控制（法律规章）导入模板.xls";
        } else if (fileName.trim().equals("xmzl")) {
            fileName = "智能审计（项目资料准备信息）导入模板.xls";
        } else if (fileName.trim().equals("sxtb")) {
            fileName = "填报模板.xlsx";
        } else if (fileName.trim().equals("zzjg")) {
            fileName = "组织架构导入模板.xls";
        } else if (fileName.trim().equals("jcsj")) {
            fileName = "基础数据导入模板.xls";
        }
//        path = path + separator +fileName;
//        File file = new File(path);
        File file = new File(filepath + '/' + fileName);
        HttpHeaders headers = new HttpHeaders();
        String fileName1 = processFileName(request, fileName);// 为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName1);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        headers.set("Content-disposition", "attachment;filename=" + fileName1);
        headers.set("Content-Length", String.valueOf(file.length()));
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK);
    }

    public static String processFileName(HttpServletRequest request, String fileNames) {
        String codedfilename = null;
        try {
            Integer index = fileNames.indexOf(".");
            if (index < 0) {
                fileNames = fileNames + ".xls";
            }
            String agent = request.getHeader("USER-AGENT");
            if (null != agent && -1 != agent.indexOf("MSIE") || null != agent && -1 != agent.indexOf("Trident")) {// ie

                String name = java.net.URLEncoder.encode(fileNames, "UTF8");

                codedfilename = name;
            } else if (null != agent && -1 != agent.indexOf("Mozilla")) {// 火狐,chrome等

                codedfilename = new String(fileNames.getBytes("UTF-8"), "iso-8859-1");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return codedfilename;
    }

    @ApiOperation(value = "系统配置-数据初始化")
    @RequestMapping(value = "/org/inihy_list", method = {RequestMethod.POST})
    public String orginiHyList(HttpServletRequest request,
                               @ApiParam(name = "pageNumber", value = "当前页数", required = true, defaultValue = "1") Integer pageNumber,
                               @ApiParam(name = "pageSize", value = "分页条数", required = true, defaultValue = "10") Integer pageSize,
                               @ApiParam(name = "pid", required = false) String pid) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblOrganization organization = tblOrganizaService.findByname("行业");
            if (pid == null || pid.equals("")) {
                pid = organization.getOrgid().toString();
            }
            if (pid == null || pid.equals("")) {
                resultMap = tblOrganizaService.findAllHYOrg(pageNumber, pageSize);
            } else {
                resultMap = tblOrganizaService.findAllHYOrgs(pageNumber, pageSize, pid);
            }
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblOrganizationMySql organization = tblOrganizaService.findByMySqlname("行业");
            if (pid == null || pid.equals("")) {
                pid = organization.getOrgid().toString();
            }
            if (pid == null || pid.equals("")) {
                resultMap = tblOrganizaService.findAllHYOrg(pageNumber, pageSize);
            } else {
                resultMap = tblOrganizaService.findAllHYOrgs(pageNumber, pageSize, pid);
            }
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @ResponseBody
    @ApiOperation(value = "系统配置-数据初始化选择")
    @RequestMapping(value = "system/startInitializationData", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    public String startInitializationData(HttpServletRequest request,
                                          @ApiParam(name = "hyId", value = "hyId", required = false) String hyId,
                                          @ApiParam(name = "orgId", value = "orgId", required = false) String orgId,
                                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                          @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        logger.info("初始化系统数据。。。。。。。");
        String results = "1";
        Jedis jedis = JedisUtil.getJedis();
        try {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
//            TblOrganizationUtil organization = null;
//            TblStaffUtil user = null;
//            if(orgId != null && !"".equals(orgId)){
//                organization = tblOrganizaService.selectFatherOrgIdByID(orgId);
//            }else{
//                organization = staff.getCurrentOrg();
//            }
//
//            if(staffId != null && !"".equals(staffId)){
//                user = tblStaffService.findById(staffId);
//            }else{
//                user = staff;
//            }
            String status = tblOrganizaService.findIniStatus(staff.getCurrentOrg().getOrgid());
            if ("0".equals(status)) {
                results = "0";
            } else {
                tblRiskcategoryService.initRiskCategory(staff.getCurrentOrg().getOrgid().toString(), new TblRiskcategory().FXSJK);
                //userService.initializationSystemData(organization,user,hyId);
                String listorgtreeJSON = RightCatch.getRightForUser(staff.getStaffid().toString());
                jedis.set(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString(), listorgtreeJSON);
                logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString() + "==value:" + jedis.get(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString()));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JedisUtil.returnResource(jedis);
        }
        return results;
    }

    @ResponseBody
    @ApiOperation(value = "系统配置-模块创建")
    @RequestMapping(value = "/flowModuleList", method = {RequestMethod.GET})
    public String flowModuleList(HttpServletRequest request, TblSystemModule module,
                                 @ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                 @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                 @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId
    ) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Map<String, Object> resultMap = tblSystemModuleService.selectPageInfoByOrgId(pageNumber, pageSize, token, staffId, module);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblSystemModuleMySql moduleMySql = new TblSystemModuleMySql();
                BeanUtils.copyProperties(module, moduleMySql);
                Map<String, Object> resultMap = tblSystemModuleService.selectMySqlPageInfoByOrgId(pageNumber, pageSize, token, staffId, moduleMySql);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @ResponseBody
    @ApiOperation(value = "系统配置-模块创建-前往新增页面")
    @RequestMapping(value = "/gotoFlowModule/insert", method = {RequestMethod.POST})
    public String gotoFlowModuleInsert(HttpServletRequest request,
                                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                       @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                                       @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) throws Exception {

        String result = null;
        Map<String, Object> resultMap = this.tblManageRightService.findRightListbyModule(token, staffId);
        if (choiceSearch == null || "".equals(choiceSearch)) {
            choiceSearch = "hide";
        }
        resultMap.put("choiceSearch", choiceSearch);
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    @ResponseBody
    @ApiOperation(value = "模块创建--选择流程--创建左侧菜单")
    @RequestMapping(value = "/flowModule/leftanalysis", method = {RequestMethod.POST})
    public String flowModuleLeftanalysisYwlc(HttpServletRequest request,
                                             @ApiParam(name = "treeName", value = "treeName", required = false) String treeName,
                                             @ApiParam(name = "orgid", value = "orgid", required = false) String orgid,
                                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.flowtree(request, token, staffId, treeName, orgid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    //标记
    @ResponseBody
    @ApiOperation(value = "模块创建--选择流程--创建右侧菜单")
    @RequestMapping(value = "/flowModule/listanalysis", method = {RequestMethod.POST})
    public String flowModuleListanalysisYwlc(HttpServletRequest request,
                                             @ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                             @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                             @ApiParam(name = "orgid", value = "所属部门id", required = false) String orgid,
                                             @ApiParam(name = "pid", value = "pid", required = false) String pid,
                                             @ApiParam(name = "faflowid", value = "faflowid", required = false) String faflowid,
                                             @ApiParam(name = "faid", value = "faid", required = false) String faid,
                                             @ApiParam(name = "flownumber", value = "flownumber", required = false) String flownumber,
                                             @ApiParam(name = "flowname", value = "flowname", required = false) String flowname,
                                             @ApiParam(name = "stutes", value = "stutes", required = false) String stutes,
                                             @ApiParam(name = "desc", value = "desc", required = false) String desc,
                                             @ApiParam(name = "view", value = "view", required = false) String view,
                                             @ApiParam(name = "belongsto", value = "belongsto", required = false) String belongsto,
                                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.listBySqlPage(token, staffId, faflowid, flowname, flownumber,
                    stutes, desc, pageNumber, pageSize, belongsto, 1, view);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "模块创建-保存")
    @RequestMapping(value = "/flowmodule/saveFlowModule", method = {RequestMethod.POST})
    @ResponseBody
    public String saveFlowModule(HttpServletRequest request, TblSystemModule module, Integer[] flowid,
                                 Integer[] flowOrderNo,
                                 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                 @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Integer count = this.tblSystemModuleService.checkReplay(module, 0, token, staffId);
                if (count > 0) {
                    return JsonBean.error("模块编号或模块名称重复，无法新增");
                }
                Map<String, Object> resultMap = this.tblSystemModuleService.saveEntity(token, staffId, module, flowid, flowOrderNo);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblSystemModuleMySql moduleMySql = new TblSystemModuleMySql();
                BeanUtils.copyProperties(module, moduleMySql);
                Integer count = this.tblSystemModuleService.checkMySqlReplay(moduleMySql, 0, token, staffId);
                if (count > 0) {
                    return JsonBean.error("模块编号或模块名称重复，无法新增");
                }
                Map<String, Object> resultMap = this.tblSystemModuleService.saveMySqlEntity(token, staffId, moduleMySql, flowid, flowOrderNo);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }

    @ApiOperation(value = "模块创建-新建流程删除")
    @RequestMapping(value = "/flowmodule/removeModelFlowRelation", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String removeModelFlowRelation(HttpServletRequest request,
                                          @RequestParam(value = "flowIds", required = true) String[] flowIds,
                                          @RequestParam(value = "modelId", required = true) Integer modelId) throws Exception {
        this.tblSystemModuleService.removeModelFlowRelation(flowIds, modelId);
        return JsonBean.success();
    }


    @ApiOperation(value = "模块创建前往修改页面")
    @RequestMapping(value = "/gotoFlowModule/goToModify", method = {RequestMethod.POST})
    public String gotoFlowModuleModify(HttpServletRequest request,
                                       @RequestParam(value = "moduleId", required = true) Integer moduleId,
                                       @RequestParam(value = "type", required = false) Integer type,
                                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                       @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblSystemModule module = this.tblSystemModuleService.findAllInfoById(moduleId);
            Map<String, Object> resultMap = this.tblManageRightService.findRightListbyModule(token, staffId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblSystemModuleMySql module = this.tblSystemModuleService.findAllMySqlInfoById(moduleId);
            Map<String, Object> resultMap = this.tblManageRightService.findRightListbyModule(token, staffId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @ResponseBody
    @ApiOperation(value = "模块创建修改保存")
    @RequestMapping(value = "/flowmodule/modifyFlowModule", method = {RequestMethod.POST})
    public String modifyFlowModule(HttpServletRequest request, TblSystemModule module, Integer[] flowid,
                                   Integer[] flowOrderNo,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                   @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Integer count = this.tblSystemModuleService.checkReplay(module, 1, token, staffId);
                if (count > 0) {
                    return "-1";
                }
                Map<String, Object> resultMap = this.tblSystemModuleService.modifyEntity(token, staffId, module, flowid, flowOrderNo);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblSystemModuleMySql moduleMySql = new TblSystemModuleMySql();
                BeanUtils.copyProperties(module, moduleMySql);
                Integer count = this.tblSystemModuleService.checkMySqlReplay(moduleMySql, 1, token, staffId);
                if (count > 0) {
                    return "-1";
                }
                Map<String, Object> resultMap = this.tblSystemModuleService.modifyMySqlEntity(token, staffId, moduleMySql, flowid, flowOrderNo);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }

    @ApiOperation(value = "模块创建启用弃用")
    @RequestMapping(value = "/flowmodule/modifyFlowModuleStatus", method = {RequestMethod.POST})
    @ResponseBody
    public String modifyFlowModuleStatus(HttpServletRequest request,
                                         @RequestParam(value = "moduleStatus", required = true) Integer moduleStatus,
                                         @RequestParam(value = "moduleId", required = true) Integer moduleId) {
        String result = null;
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        try {
            this.tblSystemModuleService.modifyFlowModifyStatus(moduleStatus, moduleId);
            resultMap.put("code", "1");
            resultMap.put("msg", "修改成功！");
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        resultMap.put("code", "0");
        resultMap.put("msg", "修改失败！");
        JSONObject jsonObj = new JSONObject(resultMap);
        result = jsonObj.toString();
        return result;
    }


    @ApiOperation(value = "模块创建下发选择")
    @RequestMapping(value = "/flowModule/gettreeorg", method = {RequestMethod.POST})
    public @ResponseBody
    String flowModuleGetTreeOeg(HttpServletRequest request,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        //TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgName");// 当前用户的机构
        Jedis jedis = JedisUtil.getJedis();
        TblStaffUtil user = DealUserToken.parseUserToken(token);
        String str = null;
        Tree tree = new Tree();
        try {
            tree.setId(user.getCurrentOrg().getOrgid());
            tree.setName(user.getCurrentOrg().getOrgname());
            tree.setOpen(true);
            tree.setIsParent(true);
            if (jedis.exists(RedisFinalUtis.COMPANYBYTREE + user.getCurrentOrg().getOrgid())) {
                str = jedis.get(RedisFinalUtis.COMPANYBYTREE + user.getCurrentOrg().getOrgid());
                List<Tree> treeList = JSON.parseArray(str, Tree.class);
                tree.setChildren(treeList);
            } else {
                List<Tree> treeList = this.treeService.findAllCompanyByTree(user.getCurrentOrg().getOrgid());
                str = JSONObject.toJSONString(treeList);
                tree.setChildren(treeList);
            }
        } finally {
            JedisUtil.returnResource(jedis);
            System.out.println(JSONObject.toJSONString(tree));
            return JSONObject.toJSONString(tree);
        }
    }


    @ApiOperation(value = "模块创建下发")
    @RequestMapping(value = "/flowmodule/saveFlowOrganizationRelation", method = {RequestMethod.POST})
    @ResponseBody
    public String saveFlowOrganizationRelation(HttpServletRequest request,
                                               @RequestParam(value = "moduleId", required = true) Integer moduleId,
                                               @RequestParam(value = "orgId", required = true) String orgId) {
        try {
            String[] orgIds = orgId.split(",");

            String modelType = this.tblSystemModuleService.findModelTypeByModuleId(moduleId);
            String rightId = null;
            if ("nk".equals(modelType)) {
                rightId = "2";
            } else if ("fxgl".equals(modelType)) {
                rightId = "70";
            } else if ("fcobc".equals(modelType)) {
                rightId = "235727";
            } else if ("nbsj".equals(modelType)) {
                rightId = "102";
            } else if ("znjk".equals(modelType)) {
                rightId = "103";
            } else {
                rightId = modelType;
            }
            HashMap<String, Object> fields = null;
            Integer count = 0;
            for (String id : orgIds) {
                // 判断是否有1及权限
                count = this.tblSystemModuleService.selectOrgManageRight(id, rightId);
                if (count == 0) {
                    if ("nk".equals(modelType) || "fxgl".equals(modelType) || "nbsj".equals(modelType)
                            || "znjk".equals(modelType)) {
                        this.tblSystemModuleService.saveOrgRightRelation(id, rightId, 1);
                    } else {
                        this.tblSystemModuleService.saveOrgRightRelation(id, rightId, 2);
                    }
                    fields = new HashMap<String, Object>();
                    fields.put("nodeId", id);
                }
                this.tblSystemModuleService.dealModuleFlowOrganizationRealtion(moduleId, id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonBean.success();
    }

    @ApiOperation(value = "模块创建取消下发选择")
    @RequestMapping(value = "/flowModule/cancelOrganizationList", method = {RequestMethod.POST})
    public String cancelOrganizationList(HttpServletRequest request,
                                         @RequestParam(value = "moduleId", required = true) Integer moduleId, TblOrganization tblOrganization,
                                         @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                Map<String, Object> resultMap = tblOrganizaService.findOrganizationInfoByModuleId(pageNumber, pageSize, tblOrganization, moduleId);
                resultMap.put("moduleId", moduleId);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        } else {
            try {
                TblOrganizationMySql tblOrganizationMySql = new TblOrganizationMySql();
                BeanUtils.copyProperties(tblOrganization, tblOrganizationMySql);
                Map<String, Object> resultMap = tblOrganizaService.findMySqlOrganizationInfoByModuleId(pageNumber, pageSize, tblOrganizationMySql, moduleId);
                resultMap.put("moduleId", moduleId);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }
    }


    @ResponseBody
    @ApiOperation(value = "模块创建取消下发")
    @RequestMapping(value = "/flowModule/removeOrgModuleRelation", method = {RequestMethod.POST})
    public String removeStaffModuleRelation(HttpServletRequest request,
                                            @RequestParam(value = "moduleId", required = true) Integer moduleId,
                                            @RequestParam(value = "orgId", required = true) String orgId) {
        try {
            this.tblSystemModuleService.removeStaffModuleRelation(moduleId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonBean.success();
    }


    @ApiOperation(value = "编号列表")
    @RequestMapping(value = "/number_list", method = {RequestMethod.POST})
    public String number_list(HttpServletRequest request,
                              @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
                              @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                              @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                              @ApiParam(name = "fatherrightid", value = "fatherrightid", required = false) String fatherrightid
    ) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        TblStaffUtil staff = DealUserToken.parseUserToken(token);
        BigDecimal orgid = staff.getCurrentOrg().getOrgid();
        if (fatherrightid == "1" || fatherrightid == null || fatherrightid == "") {
            resultMap = tblAutonoNumberService.getNumberList(orgid, new BigDecimal(1), pageNumber, pageSize);
        } else {
            resultMap = tblAutonoNumberService.getNumberList(orgid, new BigDecimal(fatherrightid), pageNumber, pageSize);
        }
        JSONObject jsonObj = new JSONObject(resultMap);
        String result = jsonObj.toString();
        return result;
    }


    @ApiOperation(value = "编号树结构")
    @RequestMapping(value = "/numberTree", method = {RequestMethod.POST})
    public @ResponseBody
    String getnumberTree(BigDecimal nodeId, String type, HttpServletRequest request,
                         @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                         @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String json = "";
        try {
            if (nodeId == null) {
                json = this.tblAutonoNumberService.getNumberTree(token, staffId, new BigDecimal(1));
            } else {
                json = this.tblAutonoNumberService.getNumberTree(token, staffId, nodeId);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    @ApiOperation(value = "编号设置-修改")
    @RequestMapping(value = "/updateNumber", method = {RequestMethod.POST})
    public @ResponseBody
    String updateNumber(HttpServletRequest request,
                        @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                        @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                        TblOrgNo tblOrgNo) {
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = tblAutonoNumberService.updateNumber(token, staffId, tblOrgNo);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            TblOrgNoMySql tblOrgNoMySql = new TblOrgNoMySql();
            BeanUtils.copyProperties(tblOrgNo, tblOrgNoMySql);
            Map<String, Object> resultMap = tblAutonoNumberService.updateMySqlNumber(token, staffId, tblOrgNoMySql);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @ApiOperation(value = "流程版本管理列表左")
    @RequestMapping(value = "/ywlc/version_left", method = {RequestMethod.POST})
    public String leftanalysisVersion(HttpServletRequest request,
                                      @ApiParam(name = "treeName", value = "treeName", required = false) String treeName,
                                      @ApiParam(name = "orgid", value = "orgid", required = false) String orgid,
                                      @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                      @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.flowtreevser(request, token, staffId, treeName, orgid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @ApiOperation(value = "流程版本管理列表右")
    @RequestMapping(value = "/nbkz/ywlc/list_version", method = {RequestMethod.POST})
    public String list_versionYwlc(HttpServletRequest request,
                                   @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                   @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                   @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                                   @ApiParam(name = "faflowid", value = "faflowid", required = true) String faflowid,
                                   @ApiParam(name = "name", value = "name", required = true) String name,
                                   @ApiParam(name = "code", value = "code", required = true) String code,
                                   @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowService.findBysqAll(token, staffId, faflowid, pageNumber,
                    pageSize, name, code);
            if (choiceSearch == null || "".equals(choiceSearch)) {
                choiceSearch = "hide";
            }
            resultMap.put("choiceSearch", choiceSearch);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "流程版本管理历史版本列表")
    @RequestMapping(value = "/ywlc/list_single_version", method = {RequestMethod.POST})
    public String list_single_versionYwlc(HttpServletRequest request, String flowid,
                                          @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                          @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                          @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                                          @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch
    ) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblFlowService.findBysqAllversion(token, staffId, flowid, pageNumber, pageSize);
            if (choiceSearch == null || "".equals(choiceSearch)) {
                choiceSearch = "hide";
            }
            resultMap.put("choiceSearch", choiceSearch);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "业务流程设置左侧菜单")
    @RequestMapping(value = "/from/processAnalysis/leftanalysis", method = {RequestMethod.POST}, produces = "application/json; charset=utf-8")
    public String leftanalysisYwlc(HttpServletRequest request,
                                   @ApiParam(name = "treeName", value = "treeName", required = false) String treeName,
                                   @ApiParam(name = "orgid", value = "orgid", required = false) String orgid,
                                   @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                   @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        logger.info("开始查询流程创建左侧tree菜单信息");
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.flowtree(request, token, staffId, treeName, orgid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    //标记
    @ResponseBody
    @ApiOperation(value = "业务流程设置右侧菜单")
    @RequestMapping(value = "/from/processAnalysis/listanalysis", method = {RequestMethod.POST})
    public String listanalysis(HttpServletRequest request,
                               @ApiParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                               @ApiParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                               @ApiParam(name = "orgid", value = "所属部门id", required = false) String orgid,
                               @ApiParam(name = "pid", value = "pid", required = false) String pid,
                               @ApiParam(name = "faflowid", value = "faflowid", required = false) String faflowid,
                               @ApiParam(name = "faid", value = "faid", required = false) String faid,
                               @ApiParam(name = "flownumber", value = "flownumber", required = false) String flownumber,
                               @ApiParam(name = "flowname", value = "flowname", required = false) String flowname,
                               @ApiParam(name = "stutes", value = "stutes", required = false) String stutes,
                               @ApiParam(name = "desc", value = "desc", required = false) String desc,
                               @ApiParam(name = "view", value = "view", required = false) String view,
                               @ApiParam(name = "departincharge", value = "departincharge", required = false) String departincharge,
                               @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                               @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.tblFlowService.listBySqlPage(token, staffId, faflowid, flowname, flownumber,
                    stutes, desc, pageNumber, pageSize, departincharge, null, null);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 业务流程设置-选择流程保存
     *
     * @param request
     * @param settingid
     * @param flowid
     * @return
     */
    @ApiOperation(value = "业务流程设置-选择流程保存")
    @RequestMapping(value = "/ywlc/saveflow", method = {RequestMethod.POST}, produces = {"application/json; charset=utf-8"})
    @ResponseBody
    public String saveflow(HttpServletRequest request,
                           @ApiParam(name = "settingid", value = "settingid", required = false) BigDecimal settingid,
                           @ApiParam(name = "flowid", value = "flowid", required = false) String flowid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (null != flowid && flowid.length() > 0) {
                TblFlow flow = this.tblFlowService.findById(flowid);
                ProcessSetting processSetting = this.processSettingService.get(settingid);
                if (null != processSetting) {
                    flow.setSettingid(processSetting.getModule());
                    this.tblFlowService.update(flow);
                    return JsonBean.success();
                } else {
                    return JsonBean.error();
                }
            } else {
                return JsonBean.error();
            }
        } else {
            if (null != flowid && flowid.length() > 0) {
                TblFlowMySql flow = this.tblFlowService.findByMySqlId(flowid);
                ProcessSettingMySql processSetting = this.processSettingService.getMy(settingid);
                if (null != processSetting) {
                    flow.setSettingid(processSetting.getModule());
                    this.tblFlowService.updateMySql(flow);
                    return JsonBean.success();
                } else {
                    return JsonBean.error();
                }
            } else {
                return JsonBean.error();
            }
        }
    }


    @ApiOperation(value = "合同流程设置列表")
    @RequestMapping(value = "/contract/typeOfContractList", method = {RequestMethod.POST})
    public String typeOfContractList(HttpServletRequest request,
                                     @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     @RequestParam(value = "choiceTypeName", required = false) String choiceTypeName,
                                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                     @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId,
                                     @ApiParam(name = "choiceSearch", value = "判断查询框显示还是隐藏默认hide", required = false) String choiceSearch) {
        String result = null;
        try {
            Map<String, Object> resultMap = tblContractTypeofService.findPageInfoList(pageNumber, pageSize, choiceTypeName, token, staffId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "合同管理根据类型-关联流程")
    @RequestMapping(value = "/process/htgl/setting", method = {RequestMethod.POST})
    public String htglprocessSetting(HttpServletRequest request,
                                     @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                     @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                     @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String result = null;
        try {
            Map<String, Object> resultMap = this.processSettingService.findByList(pageNumber, pageSize, token, staffId);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    @ApiOperation(value = "合同管理根据类型-保存关联流程")
    @RequestMapping(value = "/htgl/saveflow", method = {RequestMethod.POST})
    public @ResponseBody
    String savehtgl(HttpServletRequest request,
                    @ApiParam(name = "settingid", value = "settingid", required = false) BigDecimal settingId,
                    @ApiParam(name = "typeId", value = "typeId", required = false) String typeId) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (null != typeId && typeId.length() > 0) {
                try {
                    TblContractTypeof typeof = tblContractTypeofService.findByid(typeId);
                    ProcessSetting processSetting = processSettingService.get(settingId);
                    if (null != processSetting) {
                        typeof.setSettingid(processSetting.getModule());
                        tblContractTypeofService.updateContractTypeof(typeof);
                        processSettingService.update(processSetting);
                        return JsonBean.success();
                    } else {
                        return JsonBean.error();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return JsonBean.error();
                }
            } else {
                return JsonBean.error();
            }
        } else {
            if (null != typeId && typeId.length() > 0) {
                try {
                    TblContractTypeof typeof = tblContractTypeofService.findByid(typeId);
                    ProcessSettingMySql processSetting = processSettingService.getMy(settingId);
                    if (null != processSetting) {
                        typeof.setSettingid(processSetting.getModule());
                        TblContractTypeofMySql typeofMySql = new TblContractTypeofMySql();
                        BeanUtils.copyProperties(typeof, typeofMySql);
                        ProcessSetting processSetting1 = new ProcessSetting();
                        BeanUtils.copyProperties(processSetting, processSetting1);
                        tblContractTypeofService.updateMySqlContractTypeof(typeofMySql);
                        processSettingService.update(processSetting1);
                        return JsonBean.success();
                    } else {
                        return JsonBean.error();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return JsonBean.error();
                }
            } else {
                return JsonBean.error();
            }
        }
    }


    @ApiOperation(value = "菜单设置-系统权限")
    @RequestMapping(value = "/qxsd/mgnsqlist", method = {RequestMethod.POST}, produces = {"application/json; charset=utf-8"})
    public @ResponseBody
    String qx_gnsqTreeList(HttpServletRequest request,
                           @RequestParam(value = "id", required = false) BigDecimal id,
                           @RequestParam(value = "nodeId", required = false) BigDecimal nodeId,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                           @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        String treeJson = null;
        try {
            Map<BigDecimal, Object> map = new HashMap<BigDecimal, Object>();
            if (nodeId != null) {
                id = nodeId;
            }
            treeJson = tblManageRightService.getTreeListSettingMenu(id, map, token, staffId);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return treeJson;
    }


    @ApiOperation(value = "菜单设置-系统权限显示的列表页面子级页面数据")
    @RequestMapping(value = "/pri_list", method = {RequestMethod.POST})
    public String pri_list(HttpServletRequest request, BigDecimal fatherrightid,
                           @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                           @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            logger.info("获取节点为：" + fatherrightid);
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            List<TblManageRight> findByManageParentId = new ArrayList<TblManageRight>();
            String result = null;
            try {
                findByManageParentId = tblManageRightService.findByManageParentId(fatherrightid, token, staffId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //判断集合是否存在，如果存在列表页面展示，如果列表页面没有，证明没有子级
            if (findByManageParentId.size() > 0) {
                resultMap.put("findByManageParentId", findByManageParentId);
            } else {
                TblManageRight objTblManageRight = tblManageRightService.findById(fatherrightid.toString());
                resultMap.put("objTblManageRight", objTblManageRight);
            }
            resultMap.put("fatherrightid", fatherrightid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        } else {
            logger.info("获取节点为：" + fatherrightid);
            Map<String, Object> resultMap = new HashMap<>(0);
            List<TblManageRightMySql> findByManageParentId = new ArrayList<>();
            String result = null;
            try {
                findByManageParentId = tblManageRightService.findByMySqlManageParentId(fatherrightid, token, staffId);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //判断集合是否存在，如果存在列表页面展示，如果列表页面没有，证明没有子级
            if (findByManageParentId.size() > 0) {
                resultMap.put("findByManageParentId", findByManageParentId);
            } else {
                TblManageRightMySql objTblManageRight = tblManageRightService.findByMySqlId(fatherrightid.toString());
                resultMap.put("objTblManageRight", objTblManageRight);
            }
            resultMap.put("fatherrightid", fatherrightid);
            JSONObject jsonObj = new JSONObject(resultMap);
            result = jsonObj.toString();
            return result;
        }
    }


    @ApiOperation(value = "菜单设置-新建")
    @RequestMapping(value = "/module_name", method = {RequestMethod.POST})
    public @ResponseBody
    String module_name(HttpServletRequest request, TblManageRight vmr,
                       @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                       @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (vmr != null && vmr.getRightid() != null) {
                TblOrgRightnew orgRight = tblOrgRightService.findByTblOrgRightorgname(token, staffId, vmr.getRightname());
                if (orgRight == null) {
                    return JsonBean.success();
                }
            } else {
                TblManageRight tblManageRight = tblManageRightService.findByRightname(vmr.getRightname());
                if (tblManageRight == null) {
                    return JsonBean.success();
                }
            }
            return JsonBean.error("操作失败");
        } else {
            if (vmr != null && vmr.getRightid() != null) {
                TblOrgRightnewMySql orgRight = tblOrgRightService.findByMySqlTblOrgRightorgname(token, staffId, vmr.getRightname());
                if (orgRight == null) {
                    return JsonBean.success();
                }
            } else {
                TblManageRightMySql tblManageRight = tblManageRightService.findByMySqlRightname(vmr.getRightname());
                if (tblManageRight == null) {
                    return JsonBean.success();
                }
            }
            return JsonBean.error("操作失败");
        }
    }

    @ApiOperation(value = "菜单设置-跳转到修改页面")
    @RequestMapping(value = "/module_modify", method = {RequestMethod.POST})
    public String module_modify(HttpServletRequest request, TblManageRight vmr,
                                @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                                @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        String result = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                TblManageRight tblManageRight = tblManageRightService.findById(vmr.getRightid().toString());
                TblOrgRightnew right = tblOrgRightService.findByTblOrgRightorgid(token, staffId, vmr.getRightid().toString());
                resultMap.put("right", right);
                resultMap.put("TblManageRight", tblManageRight);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                logger.info("访问修改权限页面出错" + e.getMessage());
            }
            return result;
        } else {
            try {
                TblManageRightMySql tblManageRight = tblManageRightService.findByMySqlId(vmr.getRightid().toString());
                TblOrgRightnewMySql right = tblOrgRightService.findByMySqlTblOrgRightorgid(token, staffId, vmr.getRightid().toString());
                resultMap.put("right", right);
                resultMap.put("TblManageRight", tblManageRight);
                JSONObject jsonObj = new JSONObject(resultMap);
                result = jsonObj.toString();
            } catch (Exception e) {
                logger.info("访问修改权限页面出错" + e.getMessage());
            }
            return result;
        }
    }

    @ApiOperation(value = "菜单设置-启用弃用")
    @RequestMapping(value = "/module_xgstatus", method = {RequestMethod.POST})
    public @ResponseBody
    String gs(HttpServletRequest request, TblManageRight vmr, String status,
              @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
              @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            if (token == null && staffId == null) {
                return null;
            }
            if (status != null && status.length() > 0) {
                String right = tblOrgRightService.findByTblOrgRightreturnname(token, staffId, vmr);
                TblOrgRightnew orgright = new TblOrgRightnew();
                orgright.setRightid(Integer.parseInt(vmr.getRightid().toString()));
                orgright.setIndicatorstatus(status);
                if (right != null) {
                    orgright.setRightname(right);
                }
                tblOrgRightService.updateTblOrgRight(token, staffId, orgright);
                String listorgtreeJSON = tblManageRightService.getRightForUser(token, staffId);
                return JsonBean.success();
            }
            return JsonBean.success("操作失败");
        } else {
            if (token == null && staffId == null) {
                return null;
            }
            if (status != null && status.length() > 0) {
                String right = tblOrgRightService.findByMySqlTblOrgRightreturnname(token, staffId, vmr);
                TblOrgRightnewMySql orgright = new TblOrgRightnewMySql();
                orgright.setRightid(Integer.parseInt(vmr.getRightid().toString()));
                orgright.setIndicatorstatus(status);
                if (right != null) {
                    orgright.setRightname(right);
                }
                tblOrgRightService.updateMySqlTblOrgRight(token, staffId, orgright);
                String listorgtreeJSON = tblManageRightService.getRightForUser(token, staffId);
                return JsonBean.success();
            }
            return JsonBean.success("操作失败");
        }
    }

    @ApiOperation(value = "菜单设置-删除")
    @RequestMapping(value = "/module_del", method = {RequestMethod.POST})
    public String module_del(HttpServletRequest request, TblManageRight vmr,
                             @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                             @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) {
        logger.info("系统设置---菜单设置---删除");
        BigDecimal fatherrightid = null;
        if (vmr != null) {
            fatherrightid = vmr.getFatherrightid();
            tblManageRightService.delright(vmr);
        }
        return pri_list(request, fatherrightid, token, staffId);
    }

    //点击右上侧列表的选择，出现左下侧的功能授权
    @RequestMapping(value = "/qxsd/mgnsqorg", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "菜单设置-授权")
    public @ResponseBody
    String qx_gnsqorg(HttpServletRequest reques, BigDecimal id,
                      @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
                      @ApiParam(name = "staffId", value = "登录用户主键", required = false) String staffId) throws Exception {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            TblOrganization org = this.tblOrganizaService.findById(id.toString());
            if (null != org) {
                Map<BigDecimal, Object> map = new HashMap<BigDecimal, Object>();
                List<TblManageRight> right = tblManageRightService.findByorgid(id);
                for (TblManageRight tr : right) {
                    map.put(tr.getRightid(), 1);
                }
                String treeJson = tblOrganizaService.GetTreeOrg(id, map, staff.getCurrentOrg().getOrgid().toString());
                return treeJson;

            }
            return null;
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            TblOrganizationMySql org = this.tblOrganizaService.findByMySqlId(id.toString());
            if (null != org) {
                Map<BigDecimal, Object> map = new HashMap<BigDecimal, Object>();
                List<TblManageRightMySql> right = tblManageRightService.findByMySqlorgid(id);
                for (TblManageRightMySql tr : right) {
                    map.put(tr.getRightid(), 1);
                }
                String treeJson = tblOrganizaService.GetTreeOrg(id, map, staff.getCurrentOrg().getOrgid().toString());
                return treeJson;

            }
            return null;
        }
    }


    @RequestMapping(value = "/qxsd/qx_saveCD", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    public @ResponseBody
    String qx_save_C(String userid, String pri_id) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
//        logger.info("用户授权功能");
            if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(pri_id)) {
                TblOrganization orgn = tblOrganizaService.findById(userid);
                Jedis jedis = JedisUtil.getJedis();//获得redis客户端
                String treeJson = null;
                JSONArray json = null;
                if (null != orgn) {
                    List<TblManageRight> list = new ArrayList<TblManageRight>();
                    System.out.println(pri_id);
                    String[] priid = pri_id.split(",");
                    for (String pri : priid) {
                        TblManageRight tmang = tblManageRightService.findById(pri);
                        if (null != tmang) {
                            list.add(tmang);
                        }
                    }
                    //RightCatch.delRightFororg(orgn.getOrgid().toString());
                    if (pri_id.length() >= 1000) {
                        int index = getFromIndex(",", pri_id, 150);
                        System.out.println(index);
                        String pri_id1 = pri_id.substring(0, index);
                        String pri_id2 = pri_id.substring(index + 1, pri_id.length() - 1);
                        RightCatch.delRightFororg(orgn.getOrgid().toString(), pri_id1);
                        RightCatch.delRightFororg(orgn.getOrgid().toString(), pri_id2);
                        RightCatch.insertRightForUser(pri_id1, orgn.getOrgid().toString());
                        RightCatch.insertRightForUser(pri_id2, orgn.getOrgid().toString());
                    } else {
                        RightCatch.insertRightForUser(pri_id, orgn.getOrgid().toString());
                    }
                    orgn.getTblManageRights().clear();
                    orgn.getTblManageRights().addAll(list);
                    TblOrgRight right = new TblOrgRight();
                    for (TblManageRight org : list) {
                        right.setOrgid(orgn.getOrgid());
                        right.setRightid(org.getRightid());
                        tblOrgRightService.add(right);
                    }
                    tblOrganizaService.updateorgn(orgn);
                    //tblOrganizaService.add(orgn);

                    try {

                        List<Tree> mrList = tblManageRightService.getOrgFatherRightforRedis(orgn);
                        if (mrList != null) {
                            json = JSONArray.fromObject(mrList);
                            treeJson = json.toString();
                            jedis.set(RedisFinalUtis.MANAGEORGLIST + orgn.getOrgid(), treeJson);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        JedisUtil.returnResource(jedis);
                    }

                    return JsonBean.success();
                }
                return JsonBean.error("公司不存在");
            }
            return JsonBean.error();
        } else {
//            logger.info("用户授权功能");
            if (StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(pri_id)) {
                TblOrganizationMySql orgn = tblOrganizaService.findByMySqlId(userid);
                Jedis jedis = JedisUtil.getJedis();//获得redis客户端
                String treeJson = null;
                JSONArray json = null;
                if (null != orgn) {
                    List<TblManageRightMySql> list = new ArrayList<TblManageRightMySql>();
                    System.out.println(pri_id);
                    String[] priid = pri_id.split(",");
                    for (String pri : priid) {
                        TblManageRightMySql tmang = tblManageRightService.findByMySqlId(pri);
                        if (null != tmang) {
                            list.add(tmang);
                        }
                    }
                    //RightCatch.delRightFororg(orgn.getOrgid().toString());
                    if (pri_id.length() >= 1000) {
                        int index = getFromIndex(",", pri_id, 150);
                        System.out.println(index);
                        String pri_id1 = pri_id.substring(0, index);
                        String pri_id2 = pri_id.substring(index + 1, pri_id.length() - 1);
                        RightCatch.delRightFororg(orgn.getOrgid().toString(), pri_id1);
                        RightCatch.delRightFororg(orgn.getOrgid().toString(), pri_id2);
                        RightCatch.insertRightForUser(pri_id1, orgn.getOrgid().toString());
                        RightCatch.insertRightForUser(pri_id2, orgn.getOrgid().toString());
                    } else {
                        RightCatch.insertRightForUser(pri_id, orgn.getOrgid().toString());
                    }
                    orgn.getTblManageRightMySqls().clear();
                    orgn.getTblManageRightMySqls().addAll(list);
                    TblOrgRightMySql right = new TblOrgRightMySql();
                    for (TblManageRightMySql org : list) {
                        right.setOrgid(orgn.getOrgid());
                        right.setRightid(org.getRightid());
                        tblOrgRightService.addMySql(right);
                    }
                    tblOrganizaService.updateMySqlorgn(orgn);
                    //tblOrganizaService.add(orgn);

                    try {

                        List<Tree> mrList = tblManageRightService.getMySqlOrgFatherRightforRedis(orgn);
                        if (mrList != null) {
                            json = JSONArray.fromObject(mrList);
                            treeJson = json.toString();
                            jedis.set(RedisFinalUtis.MANAGEORGLIST + orgn.getOrgid(), treeJson);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        JedisUtil.returnResource(jedis);
                    }

                    return JsonBean.success();
                }
                return JsonBean.error("公司不存在");
            }
            return JsonBean.error();
        }
    }


    //子字符串modelStr在字符串str中第count次出现时的下标
    private int getFromIndex(String data, String str, Integer num) {
        Pattern pattern = Pattern.compile(data);
        Matcher findMatcher = pattern.matcher(str);
        //标记遍历字符串的位置
        int indexNum = 0;
        while (findMatcher.find()) {
            indexNum++;
            if (indexNum == num) {
                break;
            }
        }
        System.out.println("字符或者字符串" + str + "第" + num + "次出现的位置为：" + findMatcher.start());
        return findMatcher.start();

    }

    @ApiOperation(value = "菜单设置-保存")
    @RequestMapping(value = "/module_save", method = {RequestMethod.POST})
    public String module_save(TblManageRight viewTblManageRight,
                              @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
        TblStaffUtil staff = null;
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            try {
                staff = DealUserToken.parseUserToken(token);

                if (viewTblManageRight.getRightid() == null) {
                    //新建
                    if (viewTblManageRight.getFatherrightid() != null && viewTblManageRight.getFatherrightid().toString().equals("1")) {
                        Map<String, Object> resultMap = new HashMap<String, Object>(0);


                        viewTblManageRight.setRighturl("/fcobc/main");
                        viewTblManageRight.setFuncorder(new BigDecimal(6));
                        tblManageRightService.save(viewTblManageRight);


                        TblOrgRightnew orgright = new TblOrgRightnew();
                        orgright.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright.setRightid(Integer.parseInt(viewTblManageRight.getRightid().toString()));
                        orgright.setIndicatorstatus(viewTblManageRight.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright);


                        TblManageRight newright = new TblManageRight();
                        newright.setRightname("工作台");
                        newright.setIndicatorstatus("1");
                        newright.setFatherrightid(viewTblManageRight.getRightid());
                        newright.setRighturl("/fcobc/workSurface?mty=" + viewTblManageRight.getRightid());
                        newright.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newright);

                        TblOrgRightnew orgright1 = new TblOrgRightnew();
                        orgright1.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright1.setRightid(Integer.parseInt(newright.getRightid().toString()));
                        orgright1.setIndicatorstatus(newright.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright1);


                        TblManageRight newrightsj = new TblManageRight();
                        newrightsj.setRightname("行业数据");
                        newrightsj.setIndicatorstatus("1");
                        newrightsj.setFatherrightid(newright.getRightid());
                        newrightsj.setRighturl("submenuXMSJ44");
                        newrightsj.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newrightsj);


                        TblOrgRightnew orgright2 = new TblOrgRightnew();
                        orgright2.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright2.setRightid(Integer.parseInt(newrightsj.getRightid().toString()));
                        orgright2.setIndicatorstatus(newrightsj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright2);


                        TblManageRight newrightwyj = new TblManageRight();
                        newrightwyj.setRightname("望远镜");
                        newrightwyj.setIndicatorstatus("1");
                        newrightwyj.setFatherrightid(newrightsj.getRightid());
                        newrightwyj.setRighturl("/common/wangyuanjing?mty=" + viewTblManageRight.getRightid());
                        newrightwyj.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newrightwyj);


                        TblOrgRightnew orgright3 = new TblOrgRightnew();
                        orgright3.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright3.setRightid(Integer.parseInt(newrightwyj.getRightid().toString()));
                        orgright3.setIndicatorstatus(newrightwyj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright3);


                        TblManageRight newrightqysj = new TblManageRight();
                        newrightqysj.setRightname("企业数据");
                        newrightqysj.setIndicatorstatus("1");
                        newrightqysj.setFatherrightid(newright.getRightid());
                        newrightqysj.setRighturl("submenuXMSJ46");
                        newrightqysj.setFuncorder(new BigDecimal(2));
                        tblManageRightService.save(newrightqysj);

                        TblOrgRightnew orgright4 = new TblOrgRightnew();
                        orgright4.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright4.setRightid(Integer.parseInt(newrightqysj.getRightid().toString()));
                        orgright4.setIndicatorstatus(newrightqysj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright4);


                        TblManageRight newrightzbsj = new TblManageRight();
                        newrightzbsj.setRightname("账簿数据");
                        newrightzbsj.setIndicatorstatus("1");
                        newrightzbsj.setFatherrightid(newrightqysj.getRightid());
                        newrightzbsj.setRighturl("/prjdata/zbsj?mty=" + viewTblManageRight.getRightid());
                        newrightzbsj.setFuncorder(new BigDecimal(2));
                        tblManageRightService.save(newrightzbsj);


                        TblOrgRightnew orgright5 = new TblOrgRightnew();
                        orgright5.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright5.setRightid(Integer.parseInt(newrightzbsj.getRightid().toString()));
                        orgright5.setIndicatorstatus(newrightzbsj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright5);


                        TblManageRight newrightzbgl = new TblManageRight();
                        newrightzbgl.setRightname("账薄管理");
                        newrightzbgl.setIndicatorstatus("1");
                        newrightzbgl.setFatherrightid(newrightqysj.getRightid());
                        newrightzbgl.setRighturl("/common/listBook?pageNumber=1&mty=" + viewTblManageRight.getRightid());
                        newrightzbgl.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newrightzbgl);

                        TblOrgRightnew orgright6 = new TblOrgRightnew();
                        orgright6.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright6.setRightid(Integer.parseInt(newrightzbgl.getRightid().toString()));
                        orgright6.setIndicatorstatus(newrightzbgl.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright6);

                        TblOrganization orgn = tblOrganizaService.findById(staff.getCurrentOrg().getOrgid().toString());
                        Jedis jedis = JedisUtil.getJedis();//获得redis客户端
                        List<TblManageRight> oragnAll = new ArrayList<TblManageRight>();
                        oragnAll.add(viewTblManageRight);
                        oragnAll.add(newright);
                        oragnAll.add(newrightsj);
                        oragnAll.add(newrightwyj);
                        oragnAll.add(newrightqysj);
                        oragnAll.add(newrightzbsj);
                        oragnAll.add(newrightzbgl);
                        //orgn.getTblManageRights().addAll(oragnAll);
                        TblOrgRight right = new TblOrgRight();
                        for (TblManageRight org : oragnAll) {
                            right.setOrgid(staff.getCurrentOrg().getOrgid());
                            right.setOrgid(org.getRightid());
                            tblOrgRightService.add(right);
                        }
                        tblOrganizaService.updateorgn(orgn);
                        String treeJson = null;
                        JSONArray json = null;
                        try {
                            List<Tree> mrList = tblManageRightService.getOrgFatherRightforRedis(orgn);
                            if (mrList != null) {
                                json = JSONArray.fromObject(mrList);
                                treeJson = json.toString();
                                jedis.set(RedisFinalUtis.MANAGEORGLIST + orgn.getOrgid(), treeJson);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            JedisUtil.returnResource(jedis);
                        }


                        //List<TblManageRight> userAll = tblManageRightService.findByUserAll(staff.getStaffid().toString());
                        List<TblManageRight> userAll = new ArrayList<TblManageRight>();
                        userAll.add(viewTblManageRight);
                        userAll.add(newright);
                        userAll.add(newrightsj);
                        userAll.add(newrightwyj);
                        userAll.add(newrightqysj);
                        userAll.add(newrightzbsj);
                        userAll.add(newrightzbgl);

//                    staff.getTblManageRights().clear();
                        // staff.getTblManageRights().addAll(userAll);
                        TblManageUserRight userRight = new TblManageUserRight();
                        for (TblManageRight userR : userAll) {
                            userRight.setRightid(userR.getRightid());
                            userRight.setStaffid(staff.getStaffid());
                            tblManageRightService.inserUserRight(userRight);
                        }
                        Jedis jedi = JedisUtil.getJedis();//获得redis客户端
                        String listorgtreeJSON = tblManageRightService.getRightForUser(staff.getStaffid().toString(), staff.getCurrentOrg().getOrgid().toString());
                        jedi.set(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString(), listorgtreeJSON);
                        logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString() + "==value:" + jedi.get(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString()));
                        JedisUtil.returnResource(jedi);
                    }


                } else {
                    //TblManageRight tblManageRight = tblManageRightService.findById(viewTblManageRight.getRightid().toString());
                    TblOrgRightnew orgright = new TblOrgRightnew();
                    orgright.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                    orgright.setRightid(Integer.parseInt(viewTblManageRight.getRightid().toString()));
                    orgright.setIndicatorstatus(viewTblManageRight.getIndicatorstatus());
                    orgright.setRightname(viewTblManageRight.getRightname());

                    tblOrgRightService.updateTblOrgRights(orgright);
                    tblManageRightService.updateright(viewTblManageRight);


                    Jedis jedis = JedisUtil.getJedis();//获得redis客户端
                    String listorgtreeJSON = tblManageRightService.getRightForUser(staff.getStaffid().toString(), staff.getCurrentOrg().getOrgid().toString());
                    jedis.set(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString(), listorgtreeJSON);
                    logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString() + "==value:" + jedis.get(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString()));
                    JedisUtil.returnResource(jedis);
                }

                //mav.setViewName("redirect:/tygl/pri_list?fatherrightid="+viewTblManageRight.getFatherrightid());
            } catch (Exception e) {
                logger.info("访问权限数据action出错" + e.getMessage());
            }
            return JsonBean.success();
        } else {
            try {
                staff = DealUserToken.parseUserToken(token);

                if (viewTblManageRight.getRightid() == null) {
                    //新建
                    if (viewTblManageRight.getFatherrightid() != null && viewTblManageRight.getFatherrightid().toString().equals("1")) {
                        Map<String, Object> resultMap = new HashMap<String, Object>(0);

                        viewTblManageRight.setRighturl("/fcobc/main");
                        viewTblManageRight.setFuncorder(new BigDecimal(6));
                        tblManageRightService.save(viewTblManageRight);


                        TblOrgRightnew orgright = new TblOrgRightnew();
                        orgright.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright.setRightid(Integer.parseInt(viewTblManageRight.getRightid().toString()));
                        orgright.setIndicatorstatus(viewTblManageRight.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright);


                        TblManageRight newright = new TblManageRight();
                        newright.setRightname("工作台");
                        newright.setIndicatorstatus("1");
                        newright.setFatherrightid(viewTblManageRight.getRightid());
                        newright.setRighturl("/fcobc/workSurface?mty=" + viewTblManageRight.getRightid());
                        newright.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newright);

                        TblOrgRightnew orgright1 = new TblOrgRightnew();
                        orgright1.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright1.setRightid(Integer.parseInt(newright.getRightid().toString()));
                        orgright1.setIndicatorstatus(newright.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright1);


                        TblManageRight newrightsj = new TblManageRight();
                        newrightsj.setRightname("行业数据");
                        newrightsj.setIndicatorstatus("1");
                        newrightsj.setFatherrightid(newright.getRightid());
                        newrightsj.setRighturl("submenuXMSJ44");
                        newrightsj.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newrightsj);


                        TblOrgRightnew orgright2 = new TblOrgRightnew();
                        orgright2.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright2.setRightid(Integer.parseInt(newrightsj.getRightid().toString()));
                        orgright2.setIndicatorstatus(newrightsj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright2);


                        TblManageRight newrightwyj = new TblManageRight();
                        newrightwyj.setRightname("望远镜");
                        newrightwyj.setIndicatorstatus("1");
                        newrightwyj.setFatherrightid(newrightsj.getRightid());
                        newrightwyj.setRighturl("/common/wangyuanjing?mty=" + viewTblManageRight.getRightid());
                        newrightwyj.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newrightwyj);


                        TblOrgRightnew orgright3 = new TblOrgRightnew();
                        orgright3.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright3.setRightid(Integer.parseInt(newrightwyj.getRightid().toString()));
                        orgright3.setIndicatorstatus(newrightwyj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright3);


                        TblManageRight newrightqysj = new TblManageRight();
                        newrightqysj.setRightname("企业数据");
                        newrightqysj.setIndicatorstatus("1");
                        newrightqysj.setFatherrightid(newright.getRightid());
                        newrightqysj.setRighturl("submenuXMSJ46");
                        newrightqysj.setFuncorder(new BigDecimal(2));
                        tblManageRightService.save(newrightqysj);

                        TblOrgRightnew orgright4 = new TblOrgRightnew();
                        orgright4.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright4.setRightid(Integer.parseInt(newrightqysj.getRightid().toString()));
                        orgright4.setIndicatorstatus(newrightqysj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright4);


                        TblManageRight newrightzbsj = new TblManageRight();
                        newrightzbsj.setRightname("账簿数据");
                        newrightzbsj.setIndicatorstatus("1");
                        newrightzbsj.setFatherrightid(newrightqysj.getRightid());
                        newrightzbsj.setRighturl("/prjdata/zbsj?mty=" + viewTblManageRight.getRightid());
                        newrightzbsj.setFuncorder(new BigDecimal(2));
                        tblManageRightService.save(newrightzbsj);


                        TblOrgRightnew orgright5 = new TblOrgRightnew();
                        orgright5.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright5.setRightid(Integer.parseInt(newrightzbsj.getRightid().toString()));
                        orgright5.setIndicatorstatus(newrightzbsj.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright5);


                        TblManageRight newrightzbgl = new TblManageRight();
                        newrightzbgl.setRightname("账薄管理");
                        newrightzbgl.setIndicatorstatus("1");
                        newrightzbgl.setFatherrightid(newrightqysj.getRightid());
                        newrightzbgl.setRighturl("/common/listBook?pageNumber=1&mty=" + viewTblManageRight.getRightid());
                        newrightzbgl.setFuncorder(new BigDecimal(1));
                        tblManageRightService.save(newrightzbgl);

                        TblOrgRightnew orgright6 = new TblOrgRightnew();
                        orgright6.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                        orgright6.setRightid(Integer.parseInt(newrightzbgl.getRightid().toString()));
                        orgright6.setIndicatorstatus(newrightzbgl.getIndicatorstatus());
                        tblOrgRightService.saveTblOrgRight(orgright6);

                        TblOrganization orgn = tblOrganizaService.findById(staff.getCurrentOrg().getOrgid().toString());
                        Jedis jedis = JedisUtil.getJedis();//获得redis客户端
                        List<TblManageRight> oragnAll = new ArrayList<TblManageRight>();
                        oragnAll.add(viewTblManageRight);
                        oragnAll.add(newright);
                        oragnAll.add(newrightsj);
                        oragnAll.add(newrightwyj);
                        oragnAll.add(newrightqysj);
                        oragnAll.add(newrightzbsj);
                        oragnAll.add(newrightzbgl);
                        //orgn.getTblManageRights().addAll(oragnAll);
                        TblOrgRight right = new TblOrgRight();
                        for (TblManageRight org : oragnAll) {
                            right.setOrgid(staff.getCurrentOrg().getOrgid());
                            right.setOrgid(org.getRightid());
                            tblOrgRightService.add(right);
                        }
                        tblOrganizaService.updateorgn(orgn);
                        String treeJson = null;
                        JSONArray json = null;
                        try {
                            List<Tree> mrList = tblManageRightService.getOrgFatherRightforRedis(orgn);
                            if (mrList != null) {
                                json = JSONArray.fromObject(mrList);
                                treeJson = json.toString();
                                jedis.set(RedisFinalUtis.MANAGEORGLIST + orgn.getOrgid(), treeJson);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            JedisUtil.returnResource(jedis);
                        }


                        //List<TblManageRight> userAll = tblManageRightService.findByUserAll(staff.getStaffid().toString());
                        List<TblManageRight> userAll = new ArrayList<TblManageRight>();
                        userAll.add(viewTblManageRight);
                        userAll.add(newright);
                        userAll.add(newrightsj);
                        userAll.add(newrightwyj);
                        userAll.add(newrightqysj);
                        userAll.add(newrightzbsj);
                        userAll.add(newrightzbgl);

//                    staff.getTblManageRights().clear();
                        // staff.getTblManageRights().addAll(userAll);
                        TblManageUserRight userRight = new TblManageUserRight();
                        for (TblManageRight userR : userAll) {
                            userRight.setRightid(userR.getRightid());
                            userRight.setStaffid(staff.getStaffid());
                            tblManageRightService.inserUserRight(userRight);
                        }
                        Jedis jedi = JedisUtil.getJedis();//获得redis客户端
                        String listorgtreeJSON = tblManageRightService.getRightForUser(staff.getStaffid().toString(), staff.getCurrentOrg().getOrgid().toString());
                        jedi.set(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString(), listorgtreeJSON);
                        logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString() + "==value:" + jedi.get(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString()));
                        JedisUtil.returnResource(jedi);
                    }


                } else {
                    //TblManageRight tblManageRight = tblManageRightService.findById(viewTblManageRight.getRightid().toString());
                    TblOrgRightnew orgright = new TblOrgRightnew();
                    orgright.setOrgid(Integer.parseInt(staff.getCurrentOrg().getOrgid().toString()));
                    orgright.setRightid(Integer.parseInt(viewTblManageRight.getRightid().toString()));
                    orgright.setIndicatorstatus(viewTblManageRight.getIndicatorstatus());
                    orgright.setRightname(viewTblManageRight.getRightname());

                    tblOrgRightService.updateTblOrgRights(orgright);
                    tblManageRightService.updateright(viewTblManageRight);


                    Jedis jedis = JedisUtil.getJedis();//获得redis客户端
                    String listorgtreeJSON = tblManageRightService.getRightForUser(staff.getStaffid().toString(), staff.getCurrentOrg().getOrgid().toString());
                    jedis.set(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString(), listorgtreeJSON);
                    logger.info("redis的用户key" + RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString() + "==value:" + jedis.get(RedisFinalUtis.USERMANGERRIGHT + staff.getStaffid().toString()));
                    JedisUtil.returnResource(jedis);
                }

                //mav.setViewName("redirect:/tygl/pri_list?fatherrightid="+viewTblManageRight.getFatherrightid());
            } catch (Exception e) {
                logger.info("访问权限数据action出错" + e.getMessage());
            }
            return JsonBean.success();
        }
    }


    @ApiOperation(value = "上传图片接口")
    @RequestMapping(value = "/setting/upload", method = {RequestMethod.POST})
    public String upload(MultipartFile file) {
        String url = fileManager.upload(file);
        return url;
    }

    @PostMapping("/upload")
    public String fileUpload(MultipartFile file) {
        String attPath = "";
        String imageName;
        try {
            String fileName = file.getOriginalFilename();
            long timeInMillis = Calendar.getInstance().getTimeInMillis();
            String oldname = fileName.substring(0, fileName.lastIndexOf("."));
            imageName = fileName.replace(oldname, "" + timeInMillis);
            attPath = FtpUtil.uploadFilePath(imageName + "", file.getInputStream());
            if (StringUtils.isEmpty(attPath)) {
                return JsonBean.error("文件上传失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonBean.error("文件上传失败");
        }

        //返回当前添加的文件 前端回显
        return attPath + imageName;
    }


}



